home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Information / Specifications / TIFF / TIFF 5.0 format
Encoding:
Text File  |  1994-05-07  |  123.6 KB  |  3,134 lines  |  [TEXT/R*ch]

  1.     TIFF 5.0
  2.  
  3.  
  4. An Aldus/Microsoft Technical Memorandum:  8/8/88    Page 1
  5.  
  6.  
  7.  
  8. Preface
  9.  
  10.  
  11. This memorandum has been prepared jointly by Aldus and Microsoft in conjunction
  12. with leading scanner vendors and other interested parties.  This document does
  13. not represent a commitment on the part of either Microsoft or Aldus to provide
  14. support for this file format in any application.  When responding to specific
  15. issues raised in this memo, or when requesting additional tag or field
  16. assignments, please address your correspondence to either:
  17.  
  18.     Developers_ Desk    Windows Marketing Group
  19.     Aldus Corporation    Microsoft Corporation
  20.     411 First Ave. South    16011 NE 36th Way
  21.     Suite 200    Box 97017
  22.     Seattle, WA  98104    Redmond, WA  98073-9717
  23.     (206) 622-5500    (206) 882-8080
  24.  
  25.  
  26.  
  27. Revision Notes
  28.  
  29. This revision replaces _TIFF Revision 4._  Sections in italics are new or
  30. substantially changed in this revision.  Also new, but not in italics, are
  31. Appendices F, G, and H.
  32.  
  33. The major enhancements in TIFF 5.0 are:
  34.  
  35. 1.    Compression of grayscale and color images, for better disk space
  36. utilization.  See Appendix F.
  37.  
  38. 2.    TIFF Classes_restricted TIFF subsets that can simplify the job of the TIFF
  39. implementor.  You may wish to scan Appendix G before reading the rest of this
  40. document.   In fact, you may want to use Appendix G as your main guide, and refer
  41. back to the main body of the specification as needed for details concerning TIFF
  42. structures and field definitions.
  43.  
  44. 3.    Support for _palette color_  images.  See the TIFF Class P description in
  45. Appendix G, and the new ColorMap field description.
  46.  
  47. 4.    Two new tags that can be used to more fully define the characteristics of
  48. full color RGB data, and thereby potentially improve the quality of color image
  49. reproduction.  See Appendix H.
  50.  
  51. The organization of the document has also changed slightly.  In particular, the
  52. tags are listed in alphabetical order, within several categories, in the main
  53. body of the specification.  
  54.  
  55. As always, every attempt has been made to add functionality in such a way as to
  56. minimize incompatibility problems with older TIFF software.  In particular, many
  57. TIFF 5.0 files will be readable even by older applications that assume TIFF 4.0
  58. or an earlier version of the specification.  One exception is with files that use
  59. the new TIFF 5.0 LZW compression scheme.  Old applications will have to give up
  60. in this case, of course, and will do so _gracefully_ if they have been following
  61. the rules.  
  62.  
  63. We are grateful to all of the draft reviewers for their suggestions.  Especially
  64. helpful were Herb Weiner of Kitchen Wisdom Publishing Company, Brad Pillow of
  65. TrueVision, and engineers from Hewlett Packard and Quark.  Chris Sears of Magenta
  66. Graphics provided information which is included as Appendix H.
  67.  
  68.  
  69. Abstract
  70.  
  71. This document describes TIFF, a tag based file format that is designed to promote
  72. the interchange of digital image data.
  73.  
  74. The fields were defined primarily with desktop publishing and related
  75. applications in mind, although it is possible that other sorts of imaging
  76. applications may find TIFF to be useful.
  77.  
  78. The general scenario for which TIFF was invented assumes that applications
  79. software for scanning or painting creates a TIFF file, which can then be read and
  80. incorporated into a _document_  or _publication_  by an application such as a
  81. desktop publishing package.
  82.  
  83. TIFF is not a printer language or page description language, nor is it intended
  84. to be a general document interchange standard. The primary design goal was to
  85. provide a rich environment within which the exchange of image data between
  86. application programs can be accomplished.  This richness is required in order to
  87. take advantage of the varying capabilities of scanners and similar devices.  TIFF
  88. is therefore designed to be a superset of existing image file formats for
  89. _desktop_  scanners (and paint programs and anything else that produces images
  90. with pixels in them) and will be enhanced on a continuing basis as new
  91. capabilities arise.  A high priority has been given to structuring the data in
  92. such a way as to minimize the pain of future additions.  TIFF was designed to be
  93. an extensible interchange format.
  94.  
  95. Although TIFF is claimed to be in some sense a rich format, it can easily be used
  96. for simple scanners and applications as well, since the application developer
  97. need only be concerned with the capabilities that he requires.
  98.  
  99. TIFF is intended to be independent of specific operating systems, filing systems,
  100. compilers, and processors.  The only significant assumption is that the storage
  101. medium supports something like a _file,_  defined as a sequence of 8-bit bytes,
  102. where the bytes are numbered from 0 to N.  The largest possible TIFF file is
  103. 2**32 bytes in length.  Since TIFF uses pointers (byte offsets) quite liberally,
  104. a TIFF file is most easily read from a random access device such as a hard disk
  105. or flexible diskette, although it should be possible to read and write TIFF files
  106. on magnetic tape.
  107.  
  108. The recommended MS-DOS, UNIX, and OS/2 file extension for TIFF files is _.TIF._  
  109. The recommended Macintosh filetype is _TIFF_.  Suggestions for conventions in
  110. other computing environments are welcome.
  111.  
  112.  
  113. 1) Structure
  114.  
  115. In TIFF, individual fields are identified with a unique tag. This allows
  116. particular fields to be present or absent from the file as required by the
  117. application.  For an explanation of the rationale behind using a tag structure
  118. format, see Appendix A.
  119.  
  120. A TIFF file begins with an 8-byte _image file header_ that points to one or more
  121. _image file directories._  The image file directories contain information about
  122. the images, as well as pointers to the actual image data.
  123.  
  124. See Figure 1.
  125.  
  126. We will now describe these structures in more detail.
  127.  
  128. Image file header
  129.  
  130. A TIFF file begins with an 8-byte image file header, containing the following
  131. information:
  132.  
  133. Bytes 0-1:    The first word of the file specifies the byte order used within the
  134. file.  Legal values are:
  135.  
  136.         _II_    (hex 4949)
  137.         _MM_    (hex 4D4D)
  138.  
  139.     In the _II_  format, byte order is always from least significant to most
  140. significant, for both 16-bit and 32-bit integers.  In the _MM_  format, byte
  141. order is always from most significant to least significant, for both 16-bit and
  142. 32-bit integers.  In both formats, character strings are stored into sequential
  143. byte locations.
  144.  
  145.     All TIFF readers should support both byte orders_see Appendix G.
  146.  
  147. Bytes 2-3    The second word of the file is the TIFF _version number._  This
  148. number, 42 (2A in hex), is not to be equated with the current Revision of the
  149. TIFF specification.  In fact, the TIFF version number (42) has never changed, and
  150. probably never will.  If it ever does, it means that TIFF has changed in some way
  151. so radical that a TIFF reader should give up immediately.  The number 42 was
  152. chosen for its deep philosophical significance.  It can and should be used as
  153. additional verification that this is indeed a TIFF file.
  154.  
  155.     A TIFF file does not have a real version/revision number.  This was an
  156. explicit, conscious design decision.  In many file formats, fields take on
  157. different meanings depending on a single version number.  The problem is that as
  158. the file format _ages,_ it becomes increasingly difficult to document which
  159. fields mean what in a given version, and older software usually has to give up if
  160. it encounters a file with a newer version number.  We wanted TIFF fields to have
  161. a permanent and well-defined meaning, so that _older_ software can usually read
  162. _newer_ TIFF files.  The bottom line is lower software release costs and more
  163. reliable software.
  164.  
  165. Bytes 4-7    This long word contains the offset (in bytes) of the first Image
  166. File Directory.  The directory may be at any location in the file after the
  167. header but must begin on a word boundary.  In particular, an Image File Directory
  168. may follow the image data it describes.  Readers must simply follow the pointers,
  169. wherever they may lead.
  170.  
  171.     (The term _byte offset_ is always used in this document to refer to a
  172. location with respect to the beginning of the file.  The first byte of the file
  173. has an offset of 0.)
  174.  
  175.  
  176. Image file directory
  177.  
  178. An Image File Directory (IFD) consists of a 2-byte count of the number of entries
  179. (i.e., the number of fields), followed by a sequence of 12-byte field entries,
  180. followed by a 4-byte offset of the next Image File Directory (or 0 if none).  Do
  181. not forget to write the 4 bytes of 0 after the last IFD.
  182.  
  183. Each 12-byte IFD entry has the following format:
  184.  
  185. Bytes 0-1    contain the Tag for the field.
  186. Bytes 2-3    contain the field Type.
  187. Bytes 4-7    contain the Length (_Count_ might have been a better term) of the
  188. field.
  189. Bytes 8-11    contain the Value Offset, the file offset (in bytes) of the Value
  190. for the field.  The Value is expected to begin on a word boundary; the
  191. corresponding Value Offset will thus be an even number.  This file offset may
  192. point to anywhere in the file, including after the image data.
  193.  
  194. The entries in an IFD must be sorted in ascending order by Tag.  Note that this
  195. is not the order in which the fields are described in this document.  For a
  196. numerically ordered list of tags, see Appendix E.  The Values to which directory
  197. entries point need not be in any particular order in the file.
  198.  
  199. In order to save time and space, the Value Offset is interpreted to contain the
  200. Value instead of pointing to the Value if the Value fits into 4 bytes.  If the
  201. Value is less than 4 bytes, it is left-justified within the 4-byte Value Offset,
  202. i.e., stored in the lower-numbered bytes.  Whether or not the Value fits within 4
  203. bytes is determined by looking at the Type and Length of the field.
  204.  
  205. The Length is specified in terms of the data type, not the total number of bytes.
  206.  A single 16-bit word (SHORT) has a Length of 1, not 2, for example.  The data
  207. types and their lengths are described below:
  208.  
  209. 1 = BYTE    An 8-bit unsigned integer.
  210. 2 = ASCII    8-bit bytes that store ASCII codes; the last byte must be null.
  211. 3 = SHORT    A 16-bit (2-byte) unsigned integer.
  212. 4 = LONG    A 32-bit (4-byte) unsigned integer.
  213. 5 = RATIONAL    Two LONG_s:  the first represents the numerator of a fraction,
  214. the second the denominator.
  215.  
  216. The value of the Length part of an ASCII field entry includes the null.  If
  217. padding is necessary, the Length does not include the pad byte.  Note that there
  218. is no _count byte,_ as there is in Pascal-type strings.  The Length part of the
  219. field takes care of that.  The null is not strictly necessary, but may make
  220. things slightly simpler for C programmers.
  221.  
  222. The reader should check the type to ensure that it is what he expects.  TIFF
  223. currently allows more than 1 valid type for some fields.  For example, ImageWidth
  224. and ImageLength were specified as having type SHORT.  Very large images with more
  225. than 64K rows or columns are possible with some devices even now.  Rather than
  226. add parallel LONG tags for these fields, it is cleaner to allow both SHORT and
  227. LONG for ImageWidth and similar fields.  See Appendix G for specific
  228. recommendations.
  229.  
  230. Note that there may be more than one IFD.  Each IFD is said to define a
  231. _subfile._   One potential use of subsequent subfiles is to describe a
  232. _sub-image_  that is somehow related to the main image, such as a reduced
  233. resolution version of the image.
  234.  
  235. If you have not already done so, you may wish to turn to Appendix G to study the
  236. sample TIFF images.
  237.  
  238.  
  239. 2) Definitions
  240.  
  241. Note that the TIFF structure as described in the previous section is not specific
  242. to imaging applications in any way.  It is only the definitions of the fields
  243. themselves that jointly describe an image.
  244.  
  245. Before we begin defining the fields, we will define some basic concepts.  An
  246. image is defined to be a rectangular array of _pixels,_  each of which consists
  247. of one or more _samples._  With monochromatic data, we have one sample per pixel,
  248. and _sample_  and _pixel_  can be used interchangeably.  RGB color data contains
  249. three samples per pixel.
  250.  
  251.  
  252. 3) The Fields
  253.  
  254. This section describes the fields defined in this version of TIFF.  More fields
  255. may be added in future versions_if possible they will be added in such a way so
  256. as not to break old software that encounters a newer TIFF file.  
  257.  
  258. The documentation for each field contains the name of the field (quite arbitrary,
  259. but convenient), the Tag value, the field Type, the Number of Values (N)
  260. expected, comments describing the field, and the default, if any.  Readers must
  261. assume the default value if the field does not exist.  
  262.  
  263. _No default_ does not mean that a TIFF writer should not pay attention to the
  264. tag.  It simply means that there is no default.  If the writer has reason to
  265. believe that readers will care about the value of this field, the writer should
  266. write the field with the appropriate value.  TIFF readers can do whatever they
  267. want if they encounter a missing _no default_ field that they care about, short
  268. of refusing to import the file.  For example, if a writer does not write out a
  269. PhotometricInterpretation field, some applications will interpret the image
  270. _correctly,_ and others will display the image inverted.  This is not a good
  271. situation, and writers should be careful not to let it happen.
  272.  
  273. The fields are grouped into several categories:  basic, informational, facsimile,
  274. document storage and retrieval, and no longer recommended.  A future version of
  275. the specification may pull some of these categories into separate companion
  276. documents.
  277.  
  278. Many fields are described in this document, but most are not _required._  See
  279. Appendix G for a list of required fields, as well as examples of how to combine
  280. fields into valid and useful TIFF files.
  281. Basic Fields
  282.  
  283.  
  284. Basic fields are fields that are fundamental to the pixel architecture or visual
  285. characteristics of an image.
  286.  
  287. BitsPerSample
  288. Tag    = 258  (102)
  289. Type    = SHORT
  290. N    = SamplesPerPixel
  291.  
  292. Number of bits per sample.  Note that this tag allows a different number of bits
  293. per sample for each sample corresponding to a pixel.  For example, RGB color data
  294. could use a different number of bits per sample for each of the three color
  295. planes.  Most RGB files will have the same number of BitsPerSample for each
  296. sample.  Even in this case, be sure to include all three entries.  Writing _8_
  297. when you mean _8,8,8_ sets a bad precedent for other fields.
  298.  
  299. Default = 1.  See also SamplesPerPixel.
  300.  
  301.  
  302. ColorMap
  303. Tag    = 320 (140)
  304. Type    = SHORT
  305. N    = 3 * (2**BitsPerSample)
  306.  
  307. This tag defines a Red-Green-Blue color map for palette color images.  The
  308. palette color pixel value is used to index into all 3 subcurves.  For example, a
  309. Palette color pixel having a value of 0 would be displayed according to the 0th
  310. entry of the Red, Green, and Blue subcurves.
  311.  
  312. The subcurves are stored sequentially.  The Red entries come first, followed by
  313. the Green entries, followed by the Blue entries.  The length of each subcurve is
  314. 2**BitsPerSample.  A ColorMap entry for an 8-bit Palette color image would
  315. therefore have 3 * 256 entries.  The width of each entry is 16 bits, as implied
  316. by the type of SHORT.  0 represents the minimum intensity, and 65535 represents
  317. the maximum intensity.  Black is represented by 0,0,0, and white by 65535, 65535,
  318. 65535.  The purpose of the color map is to act as a _lookup_  table mapping pixel
  319. values from 0 to 2**BitsPerSample-1 into RGB triplets.
  320.  
  321. The ColorResponseCurves field may be used in conjunction with ColorMap to further
  322. refine the meaning of the RGB triplets in the ColorMap.  However, the
  323. ColorResponseCurves default should be sufficient in most cases.
  324.  
  325. See also PhotometricInterpretation_palette color.
  326.  
  327. No default.  ColorMap must be included in all palette color images.
  328.  
  329.  
  330. ColorResponseCurves
  331. Tag    = 301 (12D)
  332. Type    = SHORT
  333. N    = 3 * (2**BitsPerSample)
  334.  
  335. This tag defines three color response curves, one each for Red, Green and Blue
  336. color information.  The Red entries come first, followed by the Green entries,
  337. followed by the Blue entries.  The length of each subcurve is 2**BitsPerSample,
  338. using the BitsPerSample value corresponding to the respective primary.  The width
  339. of each entry is 16 bits, as implied by the type of SHORT.  0 represents the
  340. minimum intensity, and 65535 represents the maximum intensity.  Black is
  341. represented by 0,0,0, and white by 65535, 65535, 65535.  Therefore, a
  342. ColorResponseCurve entry for RGB data where each of the samples is 8 bits deep
  343. would have 3 * 256 entries, each consisting of a SHORT.
  344.  
  345. The purpose of the color response curves is to refine the content of RGB color
  346. images.
  347.  
  348. See Appendix H, section VII, for further information.
  349.  
  350. Default:  curves based on the NTSC recommended gamma of 2.2.
  351.  
  352.  
  353. Compression
  354. Tag    = 259  (103)
  355. Type    = SHORT
  356. N    = 1
  357.  
  358. 1 = No compression, but pack data into bytes as tightly as possible, with no
  359. unused bits except at the end of a row.  The bytes are stored as an array of type
  360. BYTE, for BitsPerSample <= 8, SHORT if BitsPerSample > 8 and <= 16, and LONG if
  361. BitsPerSample > 16 and <= 32.  The byte ordering of data >8 bits must be
  362. consistent with that specified in the TIFF file header (bytes 0 and 1).  _II_ 
  363. format files will have the least significant bytes preceeding the most
  364. significant bytes while _MM_  format files will have the opposite.
  365.  
  366.     If the number of bits per sample is not a power of 2, and you are willing to
  367. give up some space for better performance, you may wish to use the next higher
  368. power of 2.  For example, if your data can be represented in 6 bits, you may wish
  369. to specify that it is 8 bits deep.
  370.  
  371.     Rows are required to begin on byte boundaries.  The number of bytes per row
  372. is therefore (ImageWidth * SamplesPerPixel * BitsPerSample + 7) / 8, assuming
  373. integer arithmetic, for PlanarConfiguration=1.  Bytes per row is (ImageWidth *
  374. BitsPerSample + 7) / 8 for PlanarConfiguration=2.  
  375.  
  376.     Some graphics systems want rows to be word- or double-word-aligned. 
  377. Uncompressed TIFF rows will need to be copied into word- or double-word-padded
  378. row buffers before being passed to the graphics routines in these environments.
  379.  
  380. 2 = CCITT Group 3 1-Dimensional Modified Huffman run length encoding.  See
  381. Appendix B:  _Data Compression -- Scheme 2._  BitsPerSample must be 1, since this
  382. type of compression is defined only for bilevel images.
  383.  
  384.     When you decompress data that has been compressed by  Compression=2, you must
  385. translate white runs into 0_s and black runs into 1_s.  Therefore, the normal
  386. PhotometricInterpretation for those compression types is 0 (WhiteIsZero).  If a
  387. reader encounters a PhotometricInterpretation of 1 (BlackIsZero) for such an
  388. image, the image should be displayed and printed with black and white reversed.
  389.  
  390. 5 = LZW Compression,  for grayscale, mapped color, and full color images.  See
  391. Appendix F.
  392.  
  393. 32773 = PackBits compression, a simple byte oriented run length scheme for 1-bit
  394. images.  See Appendix C.
  395.  
  396. Data compression only applies to raster image data, as pointed to by
  397. StripOffsets.  All other TIFF information is unaffected.
  398.  
  399. Default = 1.
  400.  
  401.  
  402. GrayResponseCurve
  403. Tag    = 291 (123)
  404. Type    = SHORT
  405. N    = 2**BitsPerSample
  406.  
  407. The purpose of the gray response curve and the gray units is to provide more
  408. exact photometric interpretation information for gray scale image data, in terms
  409. of optical density.
  410.  
  411. The GrayScaleResponseUnits specifies the accuracy of the information contained in
  412. the curve.  Since optical density is specified in terms of fractional numbers,
  413. this tag is necessary to know how to interpret the stored integer information. 
  414. For example, if GrayScaleResponseUnits is set to 4 (ten-thousandths of a unit),
  415. and a GrayScaleResponseCurve number for gray level 4 is 3455, then the resulting
  416. actual value is 0.3455.  Optical densitometers typically measure densities within
  417. the range of 0.0 to 2.0.
  418.  
  419. If the gray scale response curve is known for the data in the TIFF file, and if
  420. the gray scale response of the output device is known, then an intelligent
  421. conversion can be made between the input data and the output device.  For
  422. example, the output can be made to look just like the input.  In addition, if the
  423. input image lacks contrast (as can be seen from the response curve), then
  424. appropriate contrast enhancements can be made.
  425.  
  426. The purpose of the gray scale response curve is to act as a _lookup_  table
  427. mapping values from 0 to 2**BitsPerSample-1 into specific density values.  The
  428. 0th element of the GrayResponseCurve array is used to define the gray value for
  429. all pixels having a value of 0, the 1st element of the GrayResponseCurve array is
  430. used to define the gray value for all pixels having a value of 1, and so on, up
  431. to 2**BitsPerSample-1.  If your data is _really,_ say, 7-bit data, but you are
  432. adding a 1-bit pad to each pixel to turn it into 8-bit data, everything still
  433. works:  If the data is high-order justified, half of your GrayResponseCurve
  434. entries (the odd ones, probably) will never be used, but that doesn_t hurt
  435. anything.  If the data is low-order justified, your pixel values will be between
  436. 0 and 127, so make your GrayResponseCurve accordingly.  What your curve does from
  437. 128 to 255 doesnít matter.  Note that low-order justification is probably not a
  438. good idea, however, since not all applications look at GrayResponseCurve.  Note
  439. also that LZW compression yields the same compression ratio regardless of whether
  440. the data is high-order or low-order justified.
  441.  
  442. It is permissable to have a GrayResponseCurve even for bilevel (1-bit) images. 
  443. The GrayResponseCurve will have 2 values.  It should be noted, however, that TIFF
  444. B readers are not required to pay attention to GrayResponseCurves in TIFF B
  445. files.  See Appendix G.
  446.  
  447. If both GrayResponseCurve and PhotometricInterpretation fields exist in the IFD,
  448. GrayResponseCurve values override the PhotometricInterpretation value.  But it is
  449. a good idea to write out both, since some applications do not yet pay attention
  450. to the GrayResponseCurve.
  451.  
  452. Writers may wish to purchase a Kodak Reflection Density Guide, catalog number 146
  453. 5947, available for $10 or so at prepress supply houses, to help them figure out
  454. reasonable density values for their scanner or frame grabber.  If that sounds
  455. like too much work, we recommend a curve that is linear in intensity/reflectance.
  456.  To compute reflectance from density:  R = 1 / pow(10,D).  To compute density
  457. from reflectance: D = log10 (1/R).  A typical 4-bit GrayResponseCurve may look
  458. therefore something like:  2000, 1177, 875, 699, 574, 477, 398, 331, 273, 222,
  459. 176, 135, 97, 62, 30, 0, assuming GrayResponseUnit=3.  Such a curve would be
  460. consistent with PhotometricInterpretation=1.
  461.  
  462. See also GrayResponseUnit, PhotometricInterpretation, ColorMap.
  463.  
  464.  
  465. GrayResponseUnit
  466. Tag    = 290 (122)
  467. Type    = SHORT
  468. N    = 1
  469.  
  470. 1 = Number represents tenths of a unit.
  471. 2 = Number represents hundredths of a unit.
  472. 3 = Number represents thousandths of a unit.
  473. 4 = Number represents ten-thousandths of a unit.
  474. 5 = Number represents hundred-thousandths of a unit.
  475.  
  476. Modifies GrayResponseCurve.
  477.  
  478. See also GrayResponseCurve.
  479.  
  480. For historical reasons, the default is 2.  However, for greater accuracy, we
  481. recommend using 3.
  482.  
  483.  
  484. ImageLength
  485. Tag    = 257  (101)
  486. Type    = SHORT or LONG
  487. N    = 1
  488.  
  489. The image_s length (height) in pixels (Y: vertical).  The number of rows
  490. (sometimes described as _scan lines") in the image.  See also ImageWidth.
  491.  
  492. No default.
  493.  
  494.  
  495. ImageWidth
  496. Tag    = 256  (100) 
  497. Type    = SHORT or LONG
  498. N    = 1
  499.  
  500. The image_s width, in pixels (X: horizontal).  The number of columns in the
  501. image.  See also ImageLength.
  502.  
  503. No default.
  504.  
  505.  
  506. NewSubfileType
  507. Tag =  254  (FE)
  508. Type = LONG
  509. N = 1
  510.  
  511. Replaces the old SubfileType field, due to limitations in the definition of that
  512. field.
  513.  
  514. A general indication of the kind of data that is contained in this subfile.  This
  515. field is made up of a set of 32 flag bits.  Unused bits are expected to be 0. 
  516. Bit 0 is the low-order bit.
  517.  
  518. Currently defined values are:
  519.  
  520. Bit 0     is 1 if the image is a reduced resolution version of another image in
  521. this TIFF file; else the bit is 0.
  522. Bit 1    is 1 if the image is a single page of a multi-page image (see the
  523. PageNumber tag description); else the bit is 0.
  524. Bit 2     is 1 if the image defines a transparency mask for another image in this
  525. TIFF file.  The PhotometricInterpretation value must be 4, designating a
  526. transparency mask.
  527.  
  528. These values have been defined as bit flags because they are pretty much
  529. independent of each other.  For example, it be useful to have four images in a
  530. single TIFF file: a full resolution image, a reduced resolution image, a
  531. transparency mask for the full resolution image, and a transparency mask for the
  532. reduced resolution image.  Each of the four images would have a different value
  533. for the NewSubfileType field.
  534.  
  535. Default is 0.
  536.  
  537.  
  538. PhotometricInterpretation
  539. Tag    = 262  (106)
  540. Type    = SHORT
  541. N    = 1
  542.  
  543. 0 = For bilevel and grayscale images:  0 is imaged as white.  2**BitsPerSample-1
  544. is imaged as black.  If GrayResponseCurve exists, it overrides the
  545. PhotometricInterpretation value, although it is safer to make them match, since
  546. some old applications may still be ignoring GrayResponseCurve. This is the normal
  547. value for Compression=2.
  548.  
  549. 1 = For bilevel and grayscale images:  0 is imaged as black. 2**BitsPerSample-1
  550. is imaged as white. If GrayResponseCurve exists, it overrides the
  551. PhotometricInterpretation value, although it is safer to make them match, since
  552. some old applications may still be ignoring GrayResponseCurve. If this value is
  553. specified for Compression=2, the image should display and print reversed.
  554.  
  555. 2 = RGB.  In the RGB model, a color is described as a combination of the three
  556. primary colors of light (red, green, and blue) in particular concentrations.  For
  557. each of the three samples, 0 represents minimum intensity, and 2**BitsPerSample -
  558. 1 represents maximum intensity.  Thus an RGB value of (0,0,0) represents black,
  559. and (255,255,255) represents white, assuming 8-bit samples.  For
  560. PlanarConfiguration = 1, the samples are stored in the indicated order:  first
  561. Red, then Green, then Blue.  For PlanarConfiguration = 2, the StripOffsets for
  562. the sample planes are stored in the indicated order:  first the Red sample plane
  563. StripOffsets, then the Green plane StripOffsets, then the Blue plane
  564. StripOffsets.
  565.  
  566.     The ColorResponseCurves field may be used to globally refine or alter the
  567. color balance of an RGB image without having to change the values of the pixels
  568. themselves.
  569.  
  570. 3="Palette color._   In this mode, a color is described with a single sample. 
  571. The sample is used as an index into ColorMap.  The sample is used to index into
  572. each of the red, green and blue curve tables to retrieve an RGB triplet defining
  573. an actual color.  When this PhotometricInterpretation value is used, the color
  574. response curves must also be supplied.  SamplesPerPixel must be 1.
  575.  
  576. 4 = Transparency Mask.  This means that the image is used to define an
  577. irregularly shaped region of another image in the same TIFF file. 
  578. SamplesPerPixel and BitsPerSample must be 1.  PackBits compression is
  579. recommended.  The 1-bits define the interior of the region; the 0-bits define the
  580. exterior of the region.  The Transparency Mask must have the same ImageLength and
  581. ImageWidth as the main image. 
  582.  
  583.     A reader application can use the mask to determine which parts of the image
  584. to display.  Main image pixels that correspond to 1-bits in the transparency mask
  585. are imaged to the screen or printer, but main image pixels that correspond to
  586. 0-bits in the mask are not displayed or printed. 
  587.  
  588.     It is possible to generalize the notion of a transparency mask to include
  589. partial transparency, but it is not clear that such information would be useful
  590. to a desktop publishing program.
  591.  
  592. No default.  That means that if you care if your image is displayed and printed
  593. as _normal_ vs _inverted,_ you must write out this field.  Do not rely on
  594. applications defaulting to what you want!  PhotometricInterpretation = 1 is
  595. recommended for bilevel (except for Compression=2) and grayscale images, due to
  596. popular user interfaces for changing the brightness and contrast of images. 
  597.  
  598.  
  599. PlanarConfiguration
  600. Tag    = 284  (11C)
  601. Type    = SHORT
  602. N    = 1
  603.  
  604. 1 = The sample values for each pixel are stored contiguously, so that there is a
  605. single image plane.   See PhotometricInterpretation to determine the order of the
  606. samples within the pixel data.  So, for RGB data, the data is stored
  607. RGBRGBRGB...and so on. 
  608.  
  609. 2 = The samples are stored in separate _sample planes._   The values in
  610. StripOffsets and StripByteCounts are then arranged as a 2-dimensional array, with
  611. SamplesPerPixel rows and StripsPerImage columns.    (All of the columns for row 0
  612. are stored first, followed by the columns of row 1, and so on.) 
  613. PhotometricInterpretation describes the type of data that is stored in each
  614. sample plane.  For example, RGB data is stored with the Red samples in one sample
  615. plane, the Green in another, and the Blue in another.
  616.  
  617. If SamplesPerPixel is 1, PlanarConfiguration is irrelevant, and should not be
  618. included.
  619. Default is 1.  See also BitsPerSample, SamplesPerPixel.
  620.  
  621.  
  622. Predictor
  623. Tag    = 317 (13D)
  624. Type    = SHORT
  625. N    = 1
  626.  
  627. To be used when Compression=5 (LZW).  See Appendix F.
  628.  
  629. 1 = No prediction scheme used before coding.
  630.  
  631. Default is 1.
  632.  
  633.  
  634. ResolutionUnit
  635. Tag    = 296 (128)
  636. Type    = SHORT
  637. N    = 1
  638.  
  639. To be used with XResolution and YResolution.
  640.  
  641. 1 = No absolute unit of measurement.  Used for images that may have a non-square
  642. aspect ratio, but no meaningful absolute dimensions.  The drawback of
  643. ResolutionUnit=1 is that different applications will import the image at
  644. different sizes.  Even if the decision is quite arbitrary, it might be better to
  645. use dots per inch or dots per centimeter, and pick XResolution and YResolution
  646. such that the aspect ratio is correct and the maximum dimension of the image is
  647. about four inches (the _four_ is quite arbitrary.)
  648. 2 = Inch.
  649. 3 = Centimeter.
  650.  
  651. Default is 2.  See also XResolution, YResolution.
  652.  
  653.  
  654. RowsPerStrip
  655. Tag    = 278  (116)
  656. Type    = SHORT or LONG
  657. N    = 1
  658.  
  659. The number of rows per strip.  The image data is organized into strips for fast
  660. access to individual rows when the data is compressed_though this field is valid
  661. even if the data is not compressed.
  662.  
  663. RowsPerStrip and ImageLength together tell us the number of strips in the entire
  664. image.  The equation is StripsPerImage = (ImageLength + RowsPerStrip - 1) /
  665. RowsPerStrip, assuming integer arithmetic.
  666.  
  667. Note that either SHORT or LONG values can be used to specify RowsPerStrip.  SHORT
  668. values may be used for small TIFF files.   It should be noted, however, that
  669. earlier TIFF specification revisions required LONG values and that some software
  670. may not expect SHORT values.  See Appendix G for further recommendations.
  671.  
  672. Default is 2**32 - 1, which is effectively infinity.  That is, the entire image
  673. is one strip.  We do not recommend a single strip, however.  Choose RowsPerStrip
  674. such that each strip is about 8K bytes, even if the data is not compressed, since
  675. it makes buffering simpler for readers.  The _8K_ part is pretty arbitrary, but
  676. seems to work well.
  677.  
  678. See also ImageLength, StripOffsets, StripByteCounts.
  679.  
  680.  
  681. SamplesPerPixel
  682. Tag    = 277  (115)
  683. Type    = SHORT
  684. N    = 1
  685.  
  686. The number of samples per pixel.  SamplesPerPixel is 1 for bilevel, grayscale,
  687. and palette color images.  SamplesPerPixel is 3 for RGB images.
  688.  
  689. Default = 1.  See also BitsPerSample, PhotometricInterpretation.
  690.  
  691.  
  692. StripByteCounts
  693. Tag    = 279  (117)
  694. Type    = SHORT or LONG
  695. N    = StripsPerImage for PlanarConfiguration equal to 1.
  696.     = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2
  697.  
  698. For each strip, the number of bytes in that strip.  The existence of this field
  699. greatly simplifies the chore of buffering compressed data, if the strip size is
  700. reasonable.
  701.  
  702. No default.  See also StripOffsets, RowsPerStrip.
  703.  
  704.  
  705. StripOffsets
  706. Tag    = 273  (111)
  707. Type    = SHORT or LONG
  708. N    = StripsPerImage for PlanarConfiguration equal to 1.
  709.     = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2
  710.  
  711. For each strip, the byte offset of that strip.  The offset is specified with
  712. respect to the beginning of the TIFF file.  Note that this implies that each
  713. strip has a location independent of the locations of other strips.  This feature
  714. may be useful for editing applications.  This field is the only way for a reader
  715. to find the image data, and hence must exist.
  716.  
  717. Note that either SHORT or LONG values can be used to specify the strip offsets. 
  718. SHORT values  may be used for small TIFF files.   It should be noted, however,
  719. that earlier TIFF specifications required LONG strip offsets and that some
  720. software may not expect SHORT values.  See Appendix G for further
  721. recommendations.
  722.  
  723. No default.  See also StripByteCounts, RowsPerStrip.
  724.  
  725.  
  726. XResolution
  727. Tag    = 282  (11A)
  728. Type    = RATIONAL
  729. N    = 1
  730.  
  731. The number of pixels per ResolutionUnit in the X direction, i.e., in the
  732. ImageWidth direction.  It is, of course, not mandatory that the image be actually
  733. printed at the size implied by this parameter.  It is up to the application to
  734. use this information as it wishes.
  735.  
  736. No default.  See also YResolution, ResolutionUnit.
  737.  
  738.  
  739. YResolution
  740. Tag    = 283  (11B)
  741. Type    = RATIONAL
  742. N    = 1
  743.  
  744. The number of pixels per ResolutionUnit in the Y direction, i.e., in the
  745. ImageLength direction.
  746.  
  747. No default.  See also XResolution, ResolutionUnit.
  748.  
  749.  
  750. Informational Fields
  751.  
  752.  
  753. Informational fields are fields that can provide useful information to a user,
  754. such as where the image came from.  Most are ASCII fields.  An application could
  755. have some sort of _More Info..._ dialog box to display such information.
  756.  
  757. Artist
  758. Tag    = 315  (13B)
  759. Type    = ASCII
  760.  
  761. Person who created the image.
  762.  
  763. If you need to attach a Copyright notice to an image, this is the place to do it.
  764.  In fact, you may wish to write out the contents of the field immediately after
  765. the 8-byte TIFF header.  Just make sure your IFD and field pointers are set
  766. accordingly, and you_re all set.
  767.  
  768.  
  769. DateTime
  770. Tag    = 306  (132)
  771. Type    = ASCII
  772. N    = 20
  773.  
  774. Date and time of image creation.  Use the format _YYYY:MM:DD HH:MM:SS_, with
  775. hours on a 24-hour clock, and one space character between the date and the time. 
  776. The length of the string, including the null, is 20 bytes.
  777.  
  778.  
  779. HostComputer
  780. Tag    = 316  (13C)
  781. Type    = ASCII
  782.  
  783. _ENIAC_, or whatever.  
  784.  
  785. See also Make, Model, Software.
  786.  
  787.  
  788. ImageDescription
  789. Tag    = 270 (10E)
  790. Type    = ASCII
  791.  
  792. For example, a user may wish to attach a comment such as _1988 company picnic_ to
  793. an image.
  794.  
  795. It has been suggested that this is what the newspaper and magazine industry calls
  796. a _slug._
  797.  
  798.  
  799. Make
  800. Tag    = 271  (10F)
  801. Type    = ASCII
  802.  
  803. Manufacturer of the scanner, video digitizer, or whatever.
  804.  
  805. See also Model, Software.
  806.  
  807.  
  808. Model
  809. Tag    = 272  (110)
  810. Type    = ASCII
  811.  
  812. The model name/number of the scanner, video digitizer, or whatever.
  813.  
  814. This tag is intended for user information only.
  815.  
  816. See also Make, Software.
  817.  
  818.  
  819. Software
  820. Tag    = 305  (131)
  821. Type    = ASCII
  822.  
  823. Name and release number of the software package that created the image.
  824.  
  825. This tag is intended for user information only.
  826.  
  827. See also Make, Model.
  828.  
  829.  
  830. Facsimile Fields
  831.  
  832.  
  833. Facsimile fields may be useful if you are using TIFF to store facsimile messages
  834. in _raw_ form.  They are not recommended for use in interchange with desktop
  835. publishing applications.
  836.  
  837. Compression (a basic tag)
  838. Tag    = 259  (103)
  839. Type    = SHORT
  840. N    = 1
  841.  
  842. 3 = Facsimile-compatible CCITT Group 3, exactly as specified in _Standardization
  843. of Group 3 facsimile apparatus for document transmission,_  Recommendation T.4,
  844. Volume VII, Fascicle VII.3, Terminal Equipment and Protocols for Telematic
  845. Services, The International Telegraph and Telephone Consultative Committee
  846. (CCITT), Geneva, 1985, pages 16 through 31.  Each strip must begin on a byte
  847. boundary.  (But recall that an image can be a single strip.)  Rows that are not
  848. the first row of a strip are not required to begin on a byte boundary.  The data
  849. is stored as bytes, not words_byte-reversal is not allowed.  See the
  850. Group3Options field for Group 3 options such as 1D vs 2D coding.
  851.  
  852. 4 = Facsimile-compatible CCITT Group 4, exactly as specified in _Facsimile Coding
  853. Schemes and Coding Control Functions for Group 4 Facsimile Apparatus,_ 
  854. Recommendation T.6, Volume VII, Fascicle VII.3, Terminal Equipment and Protocols
  855. for Telematic Services, The International Telegraph and Telephone Consultative
  856. Committee (CCITT), Geneva, 1985, pages 40 through 48.  Each strip must begin on a
  857. byte boundary.  Rows that are not the first row of a strip are not required to
  858. begin on a byte boundary.  The data is stored as bytes, not words.  See the
  859. Group4Options field for Group 4 options.
  860.  
  861.  
  862. Group3Options
  863. Tag    = 292  (124)
  864. Type    = LONG
  865. N    = 1
  866.  
  867. See Compression=3.  This field is made up of a set of 32 flag bits.  Unused bits
  868. are expected to be 0.  Bit 0 is the low-order bit.  It is probably not safe to
  869. try to read the file if any bit of this field is set that you don_t know the
  870. meaning of.
  871.  
  872. Bit 0    is 1 for 2-dimensional coding (else 1-dimensional is assumed).  For 2-D
  873. coding, if more than one strip is specified, each strip must begin with a
  874. 1-dimensionally coded line.  That is, RowsPerStrip should be a multiple of
  875. _Parameter K_  as documented in the CCITT specification.
  876.  
  877. Bit 1    is 1 if uncompressed mode is used.
  878.  
  879. Bit 2     is 1 if fill bits have been added as necessary before EOL codes such
  880. that EOL always ends on a byte boundary, thus ensuring an eol-sequence of a 1
  881. byte preceded by a zero nibble:  xxxx-0000 0000-0001.
  882.  
  883. Default is 0, for basic 1-dimensional coding.  See also Compression.
  884.  
  885.  
  886. Group4Options
  887. Tag    =  293  (125)
  888. Type    = LONG
  889. N    = 1
  890.  
  891. See Compression=4.  This field is made up of a set of 32 flag bits.  Unused bits
  892. are expected to be 0.  Bit 0 is the low-order bit.  It is probably not safe to
  893. try to read the file if any bit of this field is set that you don_t know the
  894. meaning of.  Gray scale and color coding schemes are under study, and will be
  895. added when finalized.
  896.  
  897. For 2-D coding, each strip is encoded as if it were a separate image.  In
  898. particular, each strip begins on a byte boundary; and the coding for the first
  899. row of a strip is encoded independently of the previous row, using horizontal
  900. codes, as if the previous row is entirely white.  Each strip ends with the 24-bit
  901. end-of-facsimile block (EOFB).
  902.  
  903. Bit 0    is unused.
  904. Bit 1    is 1 if uncompressed mode is used.
  905.  
  906. Default is 0, for basic 2-dimensional binary compression.  See also Compression.
  907.  
  908.  
  909. Document Storage and Retrieval Fields
  910.  
  911.  
  912. These fields may be useful for document storage and retrieval applications.  They
  913. are not recommended for use in interchange with desktop publishing applications.
  914.  
  915. DocumentName
  916. Tag    = 269  (10D)
  917. Type    = ASCII
  918.  
  919. The name of the document from which this image was scanned.
  920.  
  921. See also PageName.
  922.  
  923.  
  924. PageName
  925. Tag    = 285  (11D)
  926. Type    = ASCII
  927.  
  928. The name of the page from which this image was scanned.
  929.  
  930. See also DocumentName.
  931.  
  932. No default.
  933.  
  934. PageNumber
  935. Tag    = 297  (129)
  936. Type    = SHORT
  937. N    = 2
  938.  
  939. This tag is used to specify page numbers of a multiple page (e.g. facsimile)
  940. document.  Two SHORT values are specified.  The first value is the page number;
  941. the second value is the total number of pages in the document.
  942.  
  943. Note that pages need not appear in numerical order.  The first page is 0 (zero).
  944.  
  945. No default.
  946.  
  947.  
  948. XPosition
  949. Tag    = 286  (11E)
  950. Type    = RATIONAL
  951.  
  952. The X offset of the left side of the image, with respect to the left side of the
  953. page, in ResolutionUnits.
  954.  
  955. No default.  See also YPosition.
  956.  
  957.  
  958. YPosition
  959. Tag    = 287  (11F)
  960. Type    = RATIONAL
  961.  
  962. The Y offset of the top of the image, with respect to the top of the page, in
  963. ResolutionUnits.  In the TIFF coordinate scheme, the positive Y direction is
  964. down, so that YPosition is always positive.
  965.  
  966. No default.  See also XPosition.
  967.  
  968.  
  969. No Longer Recommended
  970.  
  971.  
  972. These fields are not recommended except perhaps for local use.  They should not
  973. be used for image interchange.  They have either been superseded by other fields,
  974. have been found to have serious drawbacks, or are simply not as useful as once
  975. thought.  They may be dropped entirely from a future revision of the
  976. specification.
  977.  
  978. CellLength
  979. Tag    = 265  (109)
  980. Type    = SHORT
  981. N    = 1
  982.  
  983. The length, in 1-bit samples, of the dithering/halftoning matrix.  Assumes that
  984. Threshholding = 2.
  985.  
  986. This field, plus CellWidth and Threshholding, are problematic because they cannot
  987. safely be used to reverse-engineer grayscale image data out of dithered/halftoned
  988. black-and-white data, which is their only plausible purpose.  The only _right_
  989. way to do it is to not bother with anything like these fields, and instead write
  990. some sophisticated pattern-matching software that can handle screen angles that
  991. are not multiples of 45 degrees, and other such challenging dithered/halftoned
  992. data.
  993.  
  994. So we do not recommend trying to convert dithered or halftoned data into
  995. grayscale data.  Dithered and halftoned data require careful treatment to avoid
  996. _stretch marks,_ but it can be done.  If you want grayscale images, get them
  997. directly from the scanner or frame grabber or whatever.
  998.  
  999. No default.  See also Threshholding.
  1000.  
  1001.  
  1002. CellWidth
  1003. Tag    = 264  (108)
  1004. Type    = SHORT
  1005. N    = 1
  1006.  
  1007. The width, in 1-bit samples, of the dithering/halftoning matrix.  
  1008.  
  1009. No default.  See also Threshholding.  See the comments for CellLength.
  1010.  
  1011.  
  1012. FillOrder
  1013. Tag    = 266  (10A)
  1014. Type    = SHORT
  1015. N    = 1
  1016.  
  1017. The order of data values within a byte.
  1018. 1 = most significant bits of the byte are filled first.  That is, data values (or
  1019. code words) are ordered from high order bit to low order bit within a byte.  
  1020. 2 = least significant bits are filled first.  Since little interest has been
  1021. expressed in least-significant fill order to date, and since it is easy and
  1022. inexpensive for writers to reverse bit order (use a 256-byte lookup table), we
  1023. recommend FillOrder=2 for private (non-interchange) use only.  
  1024.  
  1025. Default is FillOrder = 1.
  1026.  
  1027.  
  1028. FreeByteCounts
  1029. Tag    = 289  (121)
  1030. Type    = LONG
  1031.  
  1032. For each _free block_  in the file, the number of bytes in the block.
  1033.  
  1034. TIFF readers can ignore FreeOffsets and FreeByteCounts if present.  
  1035.  
  1036. FreeOffsets and FreeByteCounts do not constitute a remapping of the logical
  1037. address space of the file.
  1038.  
  1039. Since this information can be generated by scanning the IFDs, StripOffsets, and
  1040. StripByteCounts, FreeByteCounts and FreeOffsets are not needed.
  1041.  
  1042. In addition, it is not clear what should happen if FreeByteCounts and FreeOffsets
  1043. exist in more than one IFD.
  1044.  
  1045. See also FreeOffsets.
  1046.  
  1047.  
  1048. FreeOffsets
  1049. Tag    = 288  (120)
  1050. Type    = LONG
  1051.  
  1052. For each _free block_  in the file, its byte offset.
  1053.  
  1054. See also FreeByteCounts.
  1055.  
  1056.  
  1057. MaxSampleValue
  1058. Tag    = 281  (119)
  1059. Type    = SHORT
  1060. N    = SamplesPerPixel
  1061.  
  1062. The maximum used sample value.  For example, if the image consists of 6-bit data
  1063. low-order-justified into 8-bit bytes, MaxSampleValue will be no greater than 63.
  1064. This is field is not to be used to affect the visual appearance of the image when
  1065. displayed.  Nor should the values of this field affect the interpretation of any
  1066. other field.   Use it for statistical purposes only.
  1067.  
  1068. Default is 2**(BitsPerSample) - 1.
  1069.  
  1070.  
  1071. MinSampleValue
  1072. Tag    = 280  (118)
  1073. Type    = SHORT
  1074. N    = SamplesPerPixel
  1075.  
  1076. The minimum used sample value.  This field is not to be used to affect the visual
  1077. appearance of the image when displayed.  See the comments for MaxSampleValue.
  1078.  
  1079. Default is 0.
  1080.  
  1081.  
  1082. SubfileType
  1083. Tag    = 255  (FF)
  1084. Type    = SHORT
  1085. N    = 1
  1086.  
  1087. A general indication of the kind of data that is contained in this subfile. 
  1088. Currently defined values are:
  1089.  
  1090. 1 = full resolution image data_ImageWidth, ImageLength, and StripOffsets are
  1091. required fields; and
  1092. 2 = reduced resolution image data_ImageWidth, ImageLength, and StripOffsets are
  1093. required fields.  It is further assumed that a reduced resolution image is a
  1094. reduced version of the entire extent of the corresponding full resolution data.
  1095. 3 = single page of a multi-page image (see the PageNumber tag description).
  1096.  
  1097. Note that several image types can be found in a single TIFF file, with each
  1098. subfile described by its own IFD.
  1099.  
  1100. No default.
  1101.  
  1102. Continued use of this field is not recommended.  Writers should instead use the
  1103. new and more general NewSubfileType field.
  1104.  
  1105.  
  1106. Orientation
  1107. Tag    = 274 (112)
  1108. Type    = SHORT
  1109. N    = 1
  1110.  
  1111. 1 =    The 0th row represents the visual top of the image, and the 0th column
  1112. represents the visual left hand side.
  1113. 2 =    The 0th row represents the visual top of the image, and the 0th column
  1114. represents the visual right hand side.
  1115. 3 =    The 0th row represents the visual bottom of the image, and the 0th column
  1116. represents the visual right hand side.
  1117. 4 =    The 0th row represents the visual bottom of the image, and the 0th column
  1118. represents the visual left hand side.
  1119. 5 =    The 0th row represents the visual left hand side of the image, and the 0th
  1120. column represents the visual top.
  1121. 6 =    The 0th row represents the visual right hand side of the image, and the
  1122. 0th column represents the visual top.
  1123. 7 =    The 0th row represents the visual right hand side of the image, and the
  1124. 0th column represents the visual bottom.
  1125. 8 =    The 0th row represents the visual left hand side of the image, and the 0th
  1126. column represents the visual bottom.
  1127.  
  1128. Default is 1.
  1129.  
  1130. This field is recommended for private (non-interchange) use only.  It is
  1131. extremely costly for most readers to perform image rotation _on the fly,_ i.e.,
  1132. when importing and printing; and users of most desktop publishing applications do
  1133. not expect a file imported by the application to be altered permanently in any
  1134. way. 
  1135.  
  1136.  
  1137. Threshholding
  1138. Tag    = 263  (107)
  1139. Type    = SHORT
  1140. N    = 1
  1141.  
  1142. 1 = a bilevel _line art_  scan.  BitsPerSample must be 1.
  1143. 2 = a _dithered_  scan, usually of continuous tone data such as photographs.
  1144. BitsPerSample must be 1.
  1145. 3 = Error Diffused. 
  1146.  
  1147. Default is Threshholding = 1.  See also CellWidth, CellLength.
  1148. 4) Private Fields
  1149.  
  1150. An organization may wish to store information that is meaningful to only that
  1151. organization in a TIFF file.  Tags numbered 32768 or higher are reserved for that
  1152. purpose.  Upon request, the administrator will allocate and register a block of
  1153. private tags for an organization, to avoid possible conflicts with other
  1154. organizations.  Tags are normally allocated in blocks of five.  If that is not
  1155. enough, feel free to ask for more. You do not need to tell the TIFF administrator
  1156. or anyone else what you are going to use them for.
  1157.  
  1158. Private enumerated values can be accommodated in a similar fashion.  For example,
  1159. you may wish to experiment with a new compression scheme within TIFF. 
  1160. Enumeration constants numbered 32768 or higher are reserved for private usage. 
  1161. Upon request, the administrator will allocate and register a block of enumerated
  1162. values for a particular field (Compression, in our example), to avoid possible
  1163. conflicts.
  1164.  
  1165. Tags and values which are allocated in the private number range are not
  1166. prohibited from being included in a future revision of this specification. 
  1167. Several such instances can be found in the TIFF specification.
  1168.  
  1169. Do not choose your own tag numbers.  If you do, it could cause serious problems
  1170. some day.
  1171.  
  1172.  
  1173. 5) Image File Format Issues
  1174.  
  1175. In the quest to give users no reason NOT to buy a product, some scanning and
  1176. image editing applications overwhelm users with an incredible number of _Save
  1177. As..._ options.  Let_s get rid of as many of these as we possibly can.  For
  1178. example, a single TIFF choice should suffice once most major readers are
  1179. supporting the three TIFF compression schemes; then writers can always compress. 
  1180. And given TIFF_s flexibility, including private tag and image editing support
  1181. features, there does not seem to be any legitimate reason for continuing to write
  1182. image files using proprietary formats.
  1183.  
  1184. Along the same lines, there is no excuse for making a user have to know the file
  1185. format of a file that is to be read by an application program.  TIFF files, as
  1186. well as most other file formats, contain sufficient information to enable
  1187. software to automatically and reliably distinguish one type of file from another.
  1188.  
  1189.  
  1190. 6) For Further Information
  1191.  
  1192. Contact the Aldus Developers_ Desk for sample TIFF files, source code fragments,
  1193. and a list of features that are currently supported in Aldus products.  The Aldus
  1194. Developers_ Desk is the current _TIFF administrator._
  1195.  
  1196. Various TIFF related aids are found in Microsoft_s Windows Developers Tookit for
  1197. developers writing Windows applications.
  1198.  
  1199. Finally, a number of scanner vendors are providing various TIFF services, such as
  1200. helping to distribute the TIFF specification and answering TIFF questions. 
  1201. Contact the appropriate product manager or developer support service group.
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207. Appendix A:  Tag Structure Rationale
  1208.  
  1209.  
  1210. A file format is defined by both form (structure) and content.  The content of
  1211. TIFF consists of definitions of individual fields.  It is therefore the content
  1212. that we are ultimately interested in.  The structure merely tells us how to find
  1213. the fields.  Yet the structure deserves serious consideration for a number of
  1214. reasons that are not at all obvious at first glance.  Since the structure
  1215. described herein departs significantly from several other approaches, it may be
  1216. useful to discuss the rationale behind it.
  1217.  
  1218. The simplest, most straightforward structure for something like an image file is
  1219. a positional format.  In a positional scheme, the location of the data defines
  1220. what the data means.  For example, the field for _number of rows_ might begin at
  1221. byte offset 30 in the image file.
  1222.  
  1223. This approach is simple and easy to implement and is perfect for static
  1224. environments.  But if a significant amount of ongoing change must be
  1225. accommodated, subtle problems begin to appear.  For example, suppose that a field
  1226. must be superseded by a new, more general field.  You could bump a version number
  1227. to flag the change.  Then new software has no problem doing something sensible
  1228. with old data, and all old software will reject the new data, even software that
  1229. didn_t care about the old field.  This may seem like no more than a minor
  1230. annoyance at first glance, but causing old software to break more often than it
  1231. would really need to can be very costly and, inevitably, causes much gnashing of
  1232. teeth among customers.
  1233.  
  1234. Furthermore, it can be avoided.  One approach is to store a _valid_ flag bit for
  1235. each field.  Now you don_t have to bump the version number, as long as you can
  1236. put the new field somewhere that doesn_t disturb any of the old fields.  Old
  1237. software that didn_t care about that old field anyway can continue to function. 
  1238. (Old software that did care will of course have to give up, but this is an
  1239. unavoidable price to be paid for the sake of progress, barring total
  1240. omniscience.)
  1241.  
  1242. Another problem that crops up frequently is that certain fields are likely to
  1243. make sense only if other fields have certain values.  This is not such a serious
  1244. problem in practice; it just makes things more confusing.  Nevertheless, we note
  1245. that the _valid_ flag bits described in the previous paragraph can help to
  1246. clarify the situation.
  1247.  
  1248. Field-dumping programs can be very helpful for diagnostic purposes.  A desirable
  1249. characteristic of such a program is that it doesn_t have to know much about what
  1250. it is dumping.  In particular, it would be nice if the program could dump ASCII
  1251. data in ASCII format, integer data in integer format, and so on, without having
  1252. to teach the program about new fields all the time.  So maybe we should add a
  1253. _data type_ component to our fields, plus information on how long the field is,
  1254. so that our dump program can walk through the fields without knowing what the
  1255. fields _mean."
  1256.  
  1257. But note that if we add one more component to each field, namely a tag that tells
  1258. what the field means, we can dispense with the _valid_ flag bits, and we can also
  1259. avoid wasting space on the non-valid fields in the file.  Simple image creation
  1260. applications can write out several fields and be done.
  1261.  
  1262. We have now derived the essentials of a tag-based image file format. 
  1263.  
  1264. Finally, a caveat.  A tag based scheme cannot guarantee painless growth.  But is
  1265. does provide a useful tool to assist in the process. 
  1266.  
  1267. Appendix B:  Data Compression_Scheme 2
  1268.  
  1269.  
  1270. Abstract
  1271.  
  1272. This document describes a method for compressing bilevel data that is based on
  1273. the CCITT Group 3 1D facsimile compression scheme.
  1274.  
  1275.  
  1276. References
  1277.  
  1278. 1.    _Standardization of Group 3 facsimile apparatus for document transmission,_
  1279. Recommendation T.4, Volume VII, Fascicle VII.3, Terminal Equipment and Protocols
  1280. for Telematic Services, The International Telegraph and Telephone Consultative
  1281. Committee (CCITT), Geneva, 1985, pages 16 through 31.
  1282. 2.    _Facsimile Coding Schemes and Coding Control Functions for Group 4
  1283. Facsimile Apparatus,_ Recommendation T.6, Volume VII, Fascicle VII.3, Terminal
  1284. Equipment and Protocols for Telematic Services, The International Telegraph and
  1285. Telephone Consultative Committee (CCITT), Geneva, 1985, pages 40 through 48.
  1286.  
  1287. We do not believe that these documents are necessary in order to implement
  1288. Compression=2.  We have included (verbatim in most places) all the pertinent
  1289. information in this Appendix.  However, if you wish to order the documents, you
  1290. can write to ANSI, Attention: Sales, 1430 Broadway, New York, N.Y., 10018.  Ask
  1291. for the publication listed above_it contains both Recommendation T.4 and T.6.
  1292.  
  1293.  
  1294. Relationship to the CCITT Specifications
  1295.  
  1296. The CCITT Group 3 and Group 4 specifications describe communications protocols
  1297. for a particular class of devices.  They are not by themselves sufficient to
  1298. describe a disk data format.  Fortunately, however, the CCITT coding schemes can
  1299. be readily adapted to this different environment.  The following is one such
  1300. adaptation.  Most of the language is copied directly from the CCITT
  1301. specifications.
  1302.  
  1303.  
  1304. Coding Scheme
  1305.  
  1306. A line (row) of data is composed of a series of variable length code words.  Each
  1307. code word represents a run length of either all white or all black.  (Actually,
  1308. more than one code word may be required to code a given run, in a manner
  1309. described below.)  White runs and black runs alternate.
  1310.  
  1311. In order to ensure that the receiver (decompressor) maintains color
  1312. synchronization, all data lines will begin with a white run length code word set.
  1313.  If the actual scan line begins with a black run, a white run length of zero will
  1314. be sent (written).  Black or white run lengths are defined by the code words in
  1315. Tables 1 and 2.  The code words are of two types:  Terminating code words and
  1316. Make-up code words.  Each run length is represented by zero or more Make-up code
  1317. words followed by exactly one Terminating code word.
  1318.  
  1319. Run lengths in the range of 0 to 63 pels (pixels) are encoded with their
  1320. appropriate Terminating code word.  Note that there is a different list of code
  1321. words for black and white run lengths.
  1322.  
  1323. Run lengths in the range of 64 to 2623 (2560+63) pels are encoded first by the
  1324. Make-up code word representing the run length that is nearest to, not longer
  1325. than, that required.  This is then followed by the Terminating code word
  1326. representing the difference between the required run length and the run length
  1327. represented by the Make-up code.
  1328.  
  1329. Run lengths in the range of lengths longer than or equal to 2624 pels are coded
  1330. first by the Make-up code of 2560.  If the remaining part of the run (after the
  1331. first Make-up code of 2560) is 2560 pels or greater, additional Make-up code(s)
  1332. of 2560 are issued until the remaining part of the run becomes less than 2560
  1333. pels.  Then the remaining part of the run is encoded by Terminating code or by
  1334. Make-up code plus Terminating code, according to the range mentioned above.
  1335.  
  1336. It is considered an unrecoverable error if the sum of the run lengths for a line
  1337. does not equal the value of the ImageWidth field.
  1338.  
  1339. New rows always begin on the next available byte boundary.
  1340.  
  1341. No EOL code words are used.  No fill bits are used, except for the ignored bits
  1342. at the end of the last byte of a row.  RTC is not used.
  1343.  
  1344.  
  1345. Table 1/T.4  Terminating codes
  1346.  
  1347.  
  1348. White        Black
  1349.  run    Code     run    Code
  1350. length    word    length     word
  1351.  ----    ----    ------    ----
  1352.  
  1353.  0    00110101     0    0000110111
  1354.  1    000111     1    010
  1355.  2    0111     2    11
  1356.  3    1000     3    10
  1357.  4    1011     4    011
  1358.  5    1100     5    0011
  1359.  6    1110     6    0010
  1360.  7    1111     7    00011
  1361.  8    10011     8    000101
  1362.  9    10100     9    000100
  1363. 10    00111    10    0000100
  1364. 11    01000    11    0000101
  1365. 12    001000    12    0000111
  1366. 13    000011    13    00000100
  1367. 14    110100    14    00000111
  1368. 15    110101    15    000011000
  1369. 16    101010    16    0000010111
  1370. 17    101011    17    0000011000
  1371. 18    0100111    18    0000001000
  1372. 19    0001100    19    00001100111
  1373. 20    0001000    20    00001101000
  1374. 21    0010111    21    00001101100
  1375. 22    0000011    22    00000110111
  1376. 23    0000100    23    00000101000
  1377. 24    0101000    24    00000010111
  1378. 25    0101011    25    00000011000
  1379. 26    0010011    26    000011001010
  1380. 27    0100100    27    000011001011
  1381. 28    0011000    28    000011001100
  1382. 29    00000010    29    000011001101
  1383. 30    00000011    30    000001101000
  1384. 31    00011010    31    000001101001
  1385. 32    00011011    32    000001101010
  1386. 33    00010010    33    000001101011
  1387. 34    00010011    34    000011010010
  1388. 35    00010100    35    000011010011
  1389. 36    00010101    36    000011010100
  1390. 37    00010110    37    000011010101
  1391. 38    00010111    38    000011010110
  1392. 39    00101000    39    000011010111
  1393. 40    00101001    40    000001101100
  1394. 41    00101010    41    000001101101
  1395. 42    00101011    42    000011011010
  1396. 43    00101100    43    000011011011
  1397. 44    00101101    44    000001010100
  1398. 45    00000100    45    000001010101
  1399. 46    00000101    46    000001010110
  1400. 47    00001010    47    000001010111
  1401. 48    00001011    48    000001100100
  1402. 49    01010010    49    000001100101
  1403. 50    01010011    50    000001010010
  1404. 51    01010100    51    000001010011
  1405. 52    01010101    52    000000100100
  1406. 53    00100100    53    000000110111
  1407. 54    00100101    54    000000111000
  1408. 55    01011000    55    000000100111
  1409. 56    01011001    56    000000101000
  1410. 57    01011010    57    000001011000
  1411. 58    01011011    58    000001011001
  1412. 59    01001010    59    000000101011
  1413. 60    01001011    60    000000101100
  1414. 61    00110010    61    000001011010
  1415. 62    00110011    62    000001100110
  1416. 63    00110100    63    000001100111    
  1417.  
  1418.  
  1419.  
  1420.  
  1421. Table 2/T.4  Make-up codes
  1422.  
  1423. White        Black
  1424.  run    Code     run    Code
  1425. length    word     length    word
  1426. ------    ----    ------    ----
  1427.  
  1428.   64    11011      64    0000001111
  1429.  128    10010     128    000011001000
  1430.  192    010111     192    000011001001
  1431.  256    0110111     256    000001011011
  1432.  320    00110110     320    000000110011
  1433.  384    00110111     384    000000110100
  1434.  448    01100100     448    000000110101
  1435.  512    01100101     512    0000001101100
  1436.  576    01101000     576    0000001101101
  1437.  640    01100111     640    0000001001010
  1438.  704    011001100     704    0000001001011
  1439.  768    011001101     768    0000001001100
  1440.  832    011010010     832    0000001001101
  1441.  896    011010011     896    0000001110010
  1442.  960    011010100     960    0000001110011
  1443. 1024    011010101    1024    0000001110100
  1444. 1088    011010110    1088    0000001110101
  1445. 1152    011010111    1152    0000001110110
  1446. 1216    011011000    1216    0000001110111
  1447. 1280    011011001    1280    0000001010010
  1448. 1344    011011010    1344    0000001010011
  1449. 1408    011011011    1408    0000001010100
  1450. 1472    010011000    1472    0000001010101
  1451. 1536    010011001    1536    0000001011010
  1452. 1600    010011010    1600    0000001011011
  1453. 1664    011000    1664    0000001100100
  1454. 1728    010011011    1728    0000001100101
  1455.  EOL    000000000001     EOL    000000000001
  1456.  
  1457.  
  1458.  
  1459.  
  1460. Additional make-up codes
  1461.  
  1462. White
  1463. and
  1464. Black    Make-up
  1465. run    code
  1466. length    word
  1467. ------    ----
  1468.  
  1469. 1792    00000001000
  1470. 1856    00000001100
  1471. 1920    00000001101
  1472. 1984    000000010010
  1473. 2048    000000010011
  1474. 2112    000000010100
  1475. 2176    000000010101
  1476. 2240    000000010110
  1477. 2304    000000010111
  1478. 2368    000000011100
  1479. 2432    000000011101
  1480. 2496    000000011110
  1481. 2560    000000011111
  1482.  
  1483.  
  1484.  
  1485.  
  1486. Appendix C: Data Compression_Scheme 32773_
  1487. _PackBits_
  1488.  
  1489.  
  1490. Abstract
  1491.  
  1492. This document describes a simple compression scheme for bilevel scanned and paint
  1493. type files.
  1494.  
  1495.  
  1496. Motivation
  1497.  
  1498. The TIFF specification defines a number of compression schemes.  Compression type
  1499. 1 is really no compression, other than basic pixel packing.  Compression type 2,
  1500. based on CCITT 1D compression, is powerful, but not trivial to implement. 
  1501. Compression type 5 is typically very effective for most bilevel images, as well
  1502. as many deeper images such as palette color and grayscale images, but is also not
  1503. trivial to implement.  PackBits is a simple but often effective alternative.
  1504.  
  1505.  
  1506. Description
  1507.  
  1508. Several good schemes were already in use in various settings.  We somewhat
  1509. arbitrarily picked the Macintosh PackBits scheme.  It is byte oriented, so there
  1510. is no problem with word alignment.  And it has a good worst case behavior (at
  1511. most 1 extra byte for every 128 input bytes).  For Macintosh users, there are
  1512. toolbox utilities PackBits and UnPackBits that will do the work for you, but it
  1513. is easy to implement your own routines.
  1514.  
  1515. A pseudo code fragment to unpack might look like this:
  1516.  
  1517. Loop until you get the number of unpacked bytes you are expecting:
  1518.     Read the next source byte into n.
  1519.     If n is between 0 and 127 inclusive, copy the next n+1 bytes literally.
  1520.     Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times.
  1521.     Else if n is 128, noop.
  1522. Endloop
  1523.  
  1524. In the inverse routine, it_s best to encode a 2-byte repeat run as a replicate
  1525. run except when preceded and followed by a literal run, in which case it_s best
  1526. to merge the three into one literal run.  Always encode 3-byte repeats as
  1527. replicate runs.
  1528.  
  1529. So that_s the algorithm.  Here are some other rules:
  1530.  
  1531. —    Each row must be packed separately.  Do not compress across row boundaries. 
  1532.  
  1533. —    The number of uncompressed bytes per row is defined to be (ImageWidth + 7) /
  1534. 8.  If the uncompressed bitmap is required to have an even number of bytes per
  1535. row, decompress into word-aligned buffers.
  1536. —    If a run is larger than 128 bytes, simply encode the remainder of the run as
  1537. one or more additional replicate runs.
  1538.  
  1539. When PackBits data is uncompressed, the result should be interpreted as per
  1540. compression type 1 (no compression).
  1541.  
  1542. Appendix D
  1543.  
  1544.  
  1545. Appendix D has been deleted.  It formerly contained guidelines for passing TIFF
  1546. files on the Microsoft Windows Clipboard.  This was judged to not be a good idea,
  1547. in light of the ever-increasing size of scanned images.  Applications are instead
  1548. encouraged to employ file-based mechanisms to exchange TIFF data.  Aldus_
  1549. PageMaker, for example, implements a _File Place_ command to allow TIFF files to
  1550. be imported.
  1551.  
  1552. Appendix E:  Numerical List of TIFF Tags
  1553.  
  1554.  
  1555. NewSubfileType
  1556. Tag    =  254  (FE)
  1557. Type    = LONG
  1558. N    = 1
  1559.  
  1560. SubfileType
  1561. Tag    = 255  (FF)
  1562. Type    = SHORT
  1563. N    = 1
  1564.  
  1565. ImageWidth
  1566. Tag    = 256  (100)
  1567. Type    = SHORT or LONG
  1568. N    = 1
  1569.  
  1570. ImageLength
  1571. Tag    = 257  (101) 
  1572. Type    = SHORT or LONG
  1573. N    = 1
  1574.  
  1575. BitsPerSample
  1576. Tag    = 258  (102)
  1577. Type    = SHORT
  1578. N    = SamplesPerPixel
  1579.  
  1580. Compression
  1581. Tag    = 259  (103)
  1582. Type    = SHORT
  1583. N    = 1
  1584.  
  1585. PhotometricInterpretation
  1586. Tag    = 262  (106)
  1587. Type    = SHORT
  1588. N    = 1
  1589.  
  1590.  
  1591. Threshholding
  1592. Tag    = 263  (107)
  1593. Type    = SHORT
  1594. N    = 1
  1595.  
  1596. CellWidth
  1597. Tag    = 264  (108)
  1598. Type    = SHORT
  1599. N    = 1
  1600.  
  1601. CellLength
  1602. Tag    = 265  (109)
  1603. Type    = SHORT
  1604. N    = 1
  1605.  
  1606. FillOrder
  1607. Tag    = 266  (10A)
  1608. Type    = SHORT
  1609. N    = 1
  1610.  
  1611. DocumentName
  1612. Tag    = 269  (10D)
  1613. Type    = ASCII
  1614.  
  1615. ImageDescription
  1616. Tag    = 270 (10E)
  1617. Type    = ASCII
  1618.  
  1619. Make
  1620. Tag    = 271  (10F)
  1621. Type    = ASCII
  1622.  
  1623. Model
  1624. Tag    = 272  (110)
  1625. Type    = ASCII
  1626.  
  1627. StripOffsets
  1628. Tag    = 273  (111)
  1629. Type    = SHORT or LONG
  1630. N    = StripsPerImage for PlanarConfiguration equal to 1.
  1631.     = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2
  1632.  
  1633. Orientation
  1634. Tag    = 274 (112)
  1635. Type    = SHORT
  1636. N    = 1
  1637.  
  1638. SamplesPerPixel
  1639. Tag    = 277  (115)
  1640. Type    = SHORT
  1641. N    = 1
  1642.  
  1643. RowsPerStrip
  1644. Tag    = 278  (116)
  1645. Type    = SHORT or LONG
  1646. N    = 1
  1647.  
  1648. StripByteCounts
  1649. Tag    = 279  (117)
  1650. Type    = LONG or SHORT
  1651. N    = StripsPerImage for PlanarConfiguration equal to 1.
  1652.     = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2.
  1653.  
  1654. MinSampleValue
  1655. Tag    = 280  (118)
  1656. Type    = SHORT
  1657. N    = SamplesPerPixel
  1658.  
  1659. MaxSampleValue
  1660. Tag    = 281  (119)
  1661. Type    = SHORT
  1662. N    = SamplesPerPixel
  1663.  
  1664. XResolution
  1665. Tag    = 282  (11A)
  1666. Type    = RATIONAL
  1667. N    = 1
  1668.  
  1669. YResolution
  1670. Tag    = 283  (11B)
  1671. Type    = RATIONAL
  1672. N    = 1
  1673.  
  1674. PlanarConfiguration
  1675. Tag    = 284  (11C)
  1676. Type    = SHORT
  1677. N    = 1
  1678.  
  1679. PageName
  1680. Tag    = 285  (11D)
  1681. Type    = ASCII
  1682.  
  1683.  
  1684. XPosition
  1685. Tag    = 286  (11E)
  1686. Type    = RATIONAL
  1687.  
  1688. YPosition
  1689. Tag    = 287  (11F)
  1690. Type    = RATIONAL
  1691.  
  1692. FreeOffsets
  1693. Tag    = 288  (120)
  1694. Type    = LONG
  1695.  
  1696. FreeByteCounts
  1697. Tag    = 289  (121)
  1698. Type    = LONG
  1699.  
  1700. GrayResponseUnit
  1701. Tag    = 290 (122)
  1702. Type    = SHORT
  1703. N    = 1
  1704.  
  1705. GrayResponseCurve
  1706. Tag    = 291 (123)
  1707. Type    = SHORT
  1708. N    = 2**BitsPerSample
  1709.  
  1710. Group3Options
  1711. Tag    = 292  (124)
  1712. Type    = LONG
  1713. N    = 1
  1714.  
  1715. Group4Options
  1716. Tag    =  293  (125)
  1717. Type    = LONG
  1718. N    = 1
  1719.  
  1720. ResolutionUnit
  1721. Tag    = 296 (128)
  1722. Type    = SHORT
  1723. N    = 1
  1724.  
  1725. PageNumber
  1726. Tag    = 297  (129)
  1727. Type    = SHORT
  1728. N    = 2
  1729.  
  1730. ColorResponseCurves
  1731. Tag    = 301 (12D)
  1732. Type    = SHORT
  1733. N    = 3 * (2**BitsPerSample)
  1734.  
  1735. Software
  1736. Tag    = 305  (131)
  1737. Type    = ASCII
  1738.  
  1739. DateTime
  1740. Tag    = 306  (132)
  1741. Type    = ASCII
  1742. N    = 20
  1743.  
  1744. Artist
  1745. Tag    = 315  (13B)
  1746. Type    = ASCII
  1747.  
  1748. HostComputer
  1749. Tag    = 316  (13C)
  1750. Type    = ASCII
  1751.  
  1752. Predictor
  1753. Tag    = 317 (13D)
  1754. Type    = SHORT
  1755. N    = 1
  1756.  
  1757. WhitePoint
  1758. Tag    = 318 (13E)
  1759. Type    = RATIONAL
  1760. N    = 2
  1761.  
  1762. PrimaryChromaticities
  1763. Tag    = 319 (13F)
  1764. Type    = RATIONAL
  1765. N    = 6
  1766.  
  1767. ColorMap
  1768. Tag    = 320 (140)
  1769. Type    = SHORT
  1770. N    = 3 * (2**BitsPerSample)
  1771.  
  1772. Appendix F:  Data Compression_Scheme 5_LZW
  1773. Compression
  1774.  
  1775.  
  1776. Abstract
  1777.  
  1778. This document describes an adaptive compression scheme for raster images.
  1779.  
  1780.  
  1781. Reference
  1782.  
  1783. Terry A. Welch, _A Technique for High Performance Data Compression_, IEEE
  1784. Computer, vol. 17 no. 6 (June 1984).  Describes the basic Lempel-Ziv & Welch
  1785. (LZW) algorithm.  The author_s goal in the article is to describe a
  1786. hardware-based compressor that could be built into a disk controller or database
  1787. engine, and used on all types of data.  There is no specific discussion of raster
  1788. images.  We intend to give sufficient information in this Appendix so that the
  1789. article is not required reading.
  1790.  
  1791.  
  1792. Requirements
  1793.  
  1794. A compression scheme with the following characteristics should work well in a
  1795. desktop publishing environment:
  1796.  
  1797. —    Must work well for images of any bit depth, including images deeper than 8
  1798. bits per sample.
  1799. —    Must be effective:  an average compression ratio of at least 2:1 or better. 
  1800. And it must have a reasonable worst-case behavior, in case something really
  1801. strange is thrown at it.
  1802. —    Should not depend on small variations between pixels.  Palette color images
  1803. tend to contain abrupt changes in index values, due to common patterning and
  1804. dithering techniques.  These abrupt changes do tend to be repetitive, however,
  1805. and the scheme should make use of this fact.
  1806. —    For images generated by paint programs, the scheme should not depend on a
  1807. particular pattern width.  8x8 pixel patterns are common now, but we should not
  1808. assume that this situation will not change.
  1809. —    Must be fast.  It should not take more than 5 seconds to decompress a 100K
  1810. byte grayscale image on a 68020- or 386-based computer.  Compression can be
  1811. slower, but probably not by more than a factor of 2 or 3.
  1812. —    The level of implementation complexity must be reasonable.  We would like
  1813. something that can be implemented in no more than a couple of weeks by
  1814. a_competent software engineer with some experience in image processing.  The
  1815. compiled code for compression and decompression combined should be no more than
  1816. about 10K.
  1817. —    Does not require floating point software or hardware.
  1818.  
  1819.  
  1820. The following sections describe an algorithm based on the _LZW_  (Lempel-Ziv &
  1821. Welch) technique that meets the above requirements.  In addition meeting our
  1822. requirements, LZW has the following characteristics:
  1823.  
  1824. —    LZW is fully reversible.  All information is preserved.  But if noise or
  1825. information is removed from an image, perhaps by smoothing or zeroing some
  1826. low-order bitplanes, LZW compresses images to a smaller size.  Thus,  5-bit,
  1827. 6-bit, or 7-bit data masquerading as 8-bit data compresses better than true 8-bit
  1828. data. Smooth images also compress better than noisy images, and simple images
  1829. compress better than complex images.
  1830. Ì    On a 68082- or 386-based computer, LZW software can be written to compress
  1831. at between 30K and 80K bytes per second, depending on image characteristics.  LZW
  1832. decompression speeds are typically about 50K bytes per second.
  1833. Ì    LZW works well on bilevel images, too.  It always beats PackBits, and
  1834. generally ties CCITT 1D (Modified Huffman) compression, on our test images. 
  1835. Tying CCITT 1D is impressive in that LZW seems to be considerably faster than
  1836. CCITT 1D, at least in our implementation.
  1837. Ì    Our implementation is written in C, and compiles to about 2K bytes of object
  1838. code each for the compressor and decompressor.
  1839. Ì    One of the nice things about LZW is that it is used quite widely in other
  1840. applications such as archival programs, and is therefore more of a known
  1841. quantity.
  1842.  
  1843.  
  1844. The Algorithm
  1845.  
  1846. Each strip is compressed independently.  We strongly recommend that RowsPerStrip
  1847. be chosen such that each strip contains about 8K bytes before compression.  We
  1848. want to keep the strips small enough so that the compressed and uncompressed
  1849. versions of the strip can be kept entirely in memory even on small machines, but
  1850. large enough to maintain nearly optimal compression ratios.
  1851.  
  1852. The LZW algorithm is based on a translation table, or string table, that maps
  1853. strings of input characters into codes.  The TIFF implementation uses
  1854. variable-length codes, with a maximum code length of 12 bits.  This string table
  1855. is different for every strip, and, remarkably, does not need to be kept around
  1856. for the decompressor.  The trick is to make the decompressor automatically build
  1857. the same table as is built when compressing the data.  We use a C-like pseudocode
  1858. to describe the coding scheme:
  1859.  
  1860.     InitializeStringTable();
  1861.     WriteCode(ClearCode);
  1862.     _ = the empty string;
  1863.     for each character in the strip {
  1864.         K = GetNextCharacter();
  1865.         if _+K is in the string table {
  1866.             _ = _+K;    /* string concatenation */
  1867.         } else {
  1868.             WriteCode (CodeFromString(_));
  1869.             AddTableEntry(_+K);
  1870.             _ = K;
  1871.         }
  1872.     } /* end of for loop */
  1873.     WriteCode (CodeFromString(_));
  1874.     WriteCode (EndOfInformation);
  1875.         
  1876. That_s it.  The scheme is simple, although it is fairly challenging to implement
  1877. efficiently.  But we need a few explanations before we go on to decompression.
  1878.  
  1879. The _characters_ that make up the LZW strings are bytes containing TIFF
  1880. uncompressed (Compression=1) image data, in our implementation.  For example, if
  1881. BitsPerSample is 4, each 8-bit LZW character will contain two 4-bit pixels.  If
  1882. BitsPerSample is 16, each 16-bit pixel will span two 8-bit LZW characters.
  1883.  
  1884. (It is also possible to implement a version of LZW where the LZW character depth
  1885. equals BitsPerSample, as was described by Draft 2 of Revision 5.0.  But there is
  1886. a major problem with this approach.  If BitsPerSample is greater than 11, we can
  1887. not use 12-bit-maximum codes, so that the resulting LZW table is unacceptably
  1888. large.  Fortunately, due to the adaptive nature of LZW, we do not pay a
  1889. significant compression ratio penalty for combining several pixels into one byte
  1890. before compressing.  For example, our 4-bit sample images compressed about 3
  1891. percent worse, and our 1-bit images compressed about 5 percent better.  And it is
  1892. easier to write an LZW compressor that always uses the same character depth than
  1893. it is to write one which can handle varying depths.)
  1894.  
  1895. We can now describe some of the routine and variable references in our
  1896. pseudocode:
  1897.  
  1898. InitializeStringTable() initializes the string table to contain all possible
  1899. single-character strings.  There are 256 of them, numbered 0 through 255, since
  1900. our characters are bytes.
  1901.  
  1902. WriteCode() writes a code to the output stream.  The first code written is a
  1903. Clear code, which is defined to be code #256.
  1904.  
  1905. _ is our _prefix string._
  1906.  
  1907. GetNextCharacter() retrieves the next character value from the input stream. 
  1908. This will be number between 0 and 255, since our characters are bytes.
  1909.  
  1910. The _+_ signs indicate string concatenation.
  1911.  
  1912. AddTableEntry() adds a table entry.  (InitializeStringTable() has already put 256
  1913. entries in our table.  Each entry consists of a single-character string, and its
  1914. associated code value, which is, in our application, identical to the character
  1915. itself.  That is, the 0th entry in our table consists of the string <0>, with
  1916. corresponding code value of <0>, the 1st entry in the table consists of the
  1917. string <1>, with corresponding code value of <1>, ..., and the 255th entry in our
  1918. table consists of the string <255>, with corresponding code value of <255>.)   So
  1919. the first entry that we add to our string table will be at position 256, right? 
  1920. Well, not quite, since we will reserve code #256 for a special _Clear_ code, and
  1921. code #257 for a special _EndOfInformation_ code that we will write out at the end
  1922. of the strip.  So the first multiple-character entry added to the string table
  1923. will be at position 258.
  1924.  
  1925. Let_s try an example.  Suppose we have input data that looks like:
  1926.  
  1927. Pixel 0:    <7>
  1928. Pixel 1:    <7>
  1929. Pixel 2:    <7>
  1930. Pixel 3:    <8>
  1931. Pixel 4:    <8>
  1932. Pixel 5:    <7>
  1933. Pixel 6:    <7>
  1934. Pixel 7:    <6>
  1935. Pixel 8:    <6>
  1936.  
  1937. First, we read Pixel 0 into K.  _K is then simply <7>, since _ is the empty
  1938. string at this point.  Is the string <7> already in the string table?  Of course,
  1939. since all single character strings were put in the table by
  1940. InitializeStringTable().  So set _ equal to <7>, and go to the top of the loop.
  1941.  
  1942. Read Pixel 1 into K.  Does _K (<7><7>) exist in the string table?  No, so we get
  1943. to do some real work.  We write the code associated with _ to output (write <7>
  1944. to output), and add _K (<7><7>) to the table as entry 258.  Store K (<7>) into _.
  1945.  Note that although we have added the string consisting of Pixel 0 and Pixel 1 to
  1946. the table, we _re-use_ Pixel 1 as the beginning of the next string.
  1947.  
  1948. Back at the top of the loop.  We read Pixel 2 into K.  Does _K (<7><7>) exist in
  1949. the string table?  Yes, the entry we just added, entry 258, contains exactly
  1950. <7><7>.  So we just add K onto the end of _, so that _ is now <7><7>.
  1951.  
  1952. Back at the top of the loop.  We read Pixel 3 into K.  Does _K (<7><7><8>) exist
  1953. in the string table?  No, so write the code associated with _ (<258>) to output,
  1954. and add _K to the table as entry 259.  Store K (<8>) into _.
  1955.  
  1956. Back at the top of the loop.  We read Pixel 4 into K.  Does _K (<8><8>) exist in
  1957. the string table?  No, so write the code associated with _ (<8>) to output, and
  1958. add _K to the table as entry 260.  Store K (<8>) into _.
  1959.  
  1960. Continuing, we get the following results:
  1961.  
  1962.     After reading:    We write to output:    And add table entry:
  1963.     Pixel 0
  1964.     Pixel 1    <7>    258: <7><7>
  1965.     Pixel 2
  1966.     Pixel 3    <258>    259: <7><7><8>
  1967.     Pixel 4    <8>    260: <8><8>
  1968.     Pixel 5    <8>    261: <8><7>
  1969.     Pixel 6
  1970.     Pixel 7    <258>    262: <7><7><6>
  1971.     Pixel 8    <6>    263: <6><6>
  1972.  
  1973. WriteCode() also requires some explanation.  The output code stream,
  1974. <7><258><8><8><258><6>... in our example, should be written using as few bits as
  1975. possible.  When we are just starting out, we can use 9-bit codes, since our new
  1976. string table entries are greater than 255 but less than 512.  But when we add
  1977. table entry 512, we must switch to 10-bit codes.  Likewise, we switch to 11-bit
  1978. codes at 1024, and 12-bit codes at 2048.  We will somewhat arbitrarily limit
  1979. ourselves to 12-bit codes, so that our table can have at most 4096 entries.  If
  1980. we push it any farther, tables tend to get too large.
  1981.  
  1982. What happens if we run out of room in our string table?  This is where the
  1983. afore-mentioned Clear code comes in.  As soon as we use entry 4094, we write out
  1984. a (12-bit) Clear code.   (If we wait any longer to write the Clear code, the
  1985. decompressor might try to interpret the Clear code as a 13-bit code.)  At this
  1986. point, the compressor re-initializes the string table and starts writing out
  1987. 9-bit codes again.
  1988.  
  1989. Note that whenever you write a code and add a table entry, _ is not left empty. 
  1990. It contains exactly one character.  Be careful not to lose it when you write an
  1991. end-of-table Clear code.  You can either write it out as a 12-bit code before
  1992. writing the Clear code, in which case you will want to do it right after adding
  1993. table entry 4093, or after the clear code as a 9-bit code.  Decompression gives
  1994. the same result in either case.
  1995.  
  1996. To make things a little simpler for the decompressor, we will require that each
  1997. strip begins with a Clear code, and ends with an EndOfInformation code.
  1998.  
  1999. Every LZW-compressed strip must begin on a byte boundary.  It need not begin on a
  2000. word boundary.  LZW compression codes are stored into bytes in high-to-low-order
  2001. fashion, i.e., FillOrder is assumed to be 1.  The compressed codes are written as
  2002. bytes, not words, so that the compressed data will be identical regardless of
  2003. whether it is an _II_ or _MM_ file.
  2004.  
  2005. Note that the LZW string table is a continuously updated history of the strings
  2006. that have been encountered in the data.  It thus reflects the characteristics of
  2007. the data, providing a high degree of adaptability.
  2008.  
  2009.  
  2010. LZW Decoding
  2011.  
  2012. The procedure for decompression is a little more complicated, but still not too
  2013. bad:
  2014.         
  2015.     while ((Code = GetNextCode()) != EoiCode) {
  2016.         if (Code == ClearCode) {
  2017.             InitializeTable();
  2018.             Code = GetNextCode();
  2019.             if (Code == EoiCode)
  2020.                 break;
  2021.             WriteString(StringFromCode(Code));
  2022.             OldCode = Code;
  2023.         }  /* end of ClearCode case */
  2024.  
  2025.         else {
  2026.             if (IsInTable(Code)) {
  2027.                 WriteString(StringFromCode(Code));
  2028.                 AddStringToTable(StringFromCode(OldCode)+FirstChar(StringFromCode(Code)));
  2029.                 OldCode = Code;
  2030.             } else {
  2031.                 OutString = StringFromCode(OldCode) +
  2032. FirstChar(StringFromCode(OldCode));
  2033.                 WriteString(OutString);
  2034.                 AddStringToTable(OutString);
  2035.                 OldCode = Code;
  2036.             }
  2037.         } /* end of not-ClearCode case */
  2038.     } /* end of while loop */
  2039.  
  2040. The function GetNextCode() retrieves the next code from the LZW-coded data.  It
  2041. must keep track of bit boundaries.  It knows that the first code that it gets
  2042. will be a 9-bit code.  We add a table entry each time we get a code, so
  2043. GetNextCode() must switch over to 10-bit codes as soon as string #511 is stored
  2044. into the table.
  2045.  
  2046. The function StringFromCode() gets the string associated with a particular code
  2047. from the string table.
  2048.  
  2049. The function AddStringToTable() adds a string to the string table.  The _+_ sign
  2050. joining the two parts of the argument to AddStringToTable indicate string
  2051. concatenation.
  2052.  
  2053. StringFromCode() looks up the string associated with a given code.
  2054.  
  2055. WriteString() adds a string to the output stream.
  2056.  
  2057.  
  2058. When SamplesPerPixel Is Greater Than 1
  2059.  
  2060. We have so far described the compression scheme as if SamplesPerPixel were always
  2061. 1, as will be be the case with palette color and grayscale images.  But what do
  2062. we do with RGB image data?
  2063.  
  2064. Tests on our sample images indicate that the LZW compression ratio is nearly
  2065. identical regardless of whether PlanarConfiguration=1 or PlanarConfiguration=2,
  2066. for RGB images.  So use whichever configuration you prefer, and simply compress
  2067. the bytes in the strip.
  2068.  
  2069. It is worth cautioning that compression ratios on our test RGB images were
  2070. disappointing low: somewhere between 1.1 to 1 and 1.5 to 1, depending on the
  2071. image.  Vendors are urged to do what they can to remove as much noise from their
  2072. images as possible.  Preliminary tests indicate that significantly better
  2073. compression ratios are possible with less noisy images.  Even something as simple
  2074. as zeroing out one or two least-significant bitplanes may be quite effective,
  2075. with little or no perceptible image degradation.
  2076.  
  2077.  
  2078. Implementation
  2079.  
  2080. The exact structure of the string table and the method used to determine if a
  2081. string is already in the table are probably the most significant design decisions
  2082. in the implementation of a LZW compressor and decompressor.  Hashing has been
  2083. suggested as a useful technique for the compressor.  We have chosen a tree based
  2084. approach, with good results.  The decompressor is actually more straightforward,
  2085. as well as faster, since no search is involved_strings can be accessed directly
  2086. by code value.
  2087.  
  2088.  
  2089. Performance
  2090.  
  2091. Many people do not realize that the performance of any compression scheme depends
  2092. greatly on the type of data to which it is applied.  A scheme that works well on
  2093. one data set may do poorly on the next.
  2094.  
  2095. But since we do not want to burden the world with too many compression schemes,
  2096. an adaptive scheme such as LZW that performs quite well on a wide range of images
  2097. is very desirable.  LZW may not always give optimal compression ratios, but its
  2098. adaptive nature and relative simplicity seem to make it a good choice.
  2099.  
  2100. Experiments thus far indicate that we can expect compression ratios of between
  2101. 1.5 and 3.0 to 1 from LZW, with no loss of data, on continuous tone grayscale
  2102. scanned images.  If we zero the least significant one or two bitplanes of 8-bit
  2103. data, higher ratios can be achieved.  These bitplanes often consist chiefly of
  2104. noise, in which case little or no loss in image quality will be perceived. 
  2105. Palette color images created in a paint program generally compress much better
  2106. than continuous tone scanned images, since paint images tend to be more
  2107. repetitive.  It is not unusual to achieve compression ratios of 10 to 1 or better
  2108. when using LZW on palette color paint images.
  2109.  
  2110. By way of comparison, PackBits, used in TIFF for black and white bilevel images,
  2111. does not do well on color paint images, much less continuous tone grayscale and
  2112. color images.  1.2 to 1 seemed to be about average for 4-bit images, and 8-bit
  2113. images are worse.
  2114.  
  2115. It has been suggested that the CCITT 1D scheme could be used for continuous tone
  2116. images, by compressing each bitplane separately.  No doubt some compression could
  2117. be achieved, but it seems unlikely that a scheme based on a fixed table that is
  2118. optimized for short black runs separated by longer white runs would be a very
  2119. good choice on any of the bitplanes.  It would do quite well on the high-order
  2120. bitplanes (but so would a simpler scheme like PackBits), and would do quite
  2121. poorly on the low-order bitplanes.  We believe that the compression ratios would
  2122. generally not be very impressive, and the process would in addition be quite
  2123. slow.  Splitting the pixels into bitplanes and putting them back together is
  2124. somewhat expensive, and the coding is also fairly slow when implemented in
  2125. software.
  2126.  
  2127. Another approach that has been suggested uses uses a 2D differencing step
  2128. following by coding the differences using a fixed table of variable-length codes.
  2129.  This type of scheme works quite well on many 8-bit grayscale images, and is
  2130. probably simpler to implement than LZW.  But it has a number of disadvantages
  2131. when used on a wide variety of images.  First, it is not adaptive.  This makes a
  2132. big difference when compressing data such as 8-bit images that have been
  2133. _sharpened_ using one of the standard techniques.  Such images tend to get larger
  2134. instead of smaller when compressed.  Another disadvantage of these schemes is
  2135. that they do not do well with a wide range of bit depths.  The built-in code
  2136. table has to be optimized for a particular bit depth in order to be effective.
  2137.  
  2138. Finally, we should mention _lossy_ compression schemes.  Extensive research has
  2139. been done in the area of lossy, or non-information-preserving image compression. 
  2140. These techniques generally yield much higher compression ratios than can be
  2141. achieved by fully-reversible, information-preserving image compression techniques
  2142. such as PackBits and LZW.  Some disadvantages:  many of the lossy techniques are
  2143. so computationally expensive that hardware assists are required.  Others are so
  2144. complicated that most microcomputer software vendors could not afford either the
  2145. expense of implementation or the increase in application object code size.  Yet
  2146. others sacrifice enough image quality to make them unsuitable for publishing use.
  2147.  
  2148.  
  2149. In spite of these difficulties, we believe that there will one day be a
  2150. standardized lossy compression scheme for full color images that will be usable
  2151. for publishing applications on microcomputers.  An International Standards
  2152. Organization group, ISO/IEC/JTC1/SC2/WG8, in cooperation with CCITT Study Group
  2153. VIII, is hard at work on a scheme that might be appropriate.  We expect that a
  2154. future revision of TIFF will incorporate this scheme once it is finalized, if it
  2155. turns out to satisfy the needs of desktop publishers and others in the
  2156. microcomputer community.  This will augment, not replace, LZW as an approved TIFF
  2157. compression scheme.  LZW will very likely remain the scheme of choice for Palette
  2158. color images, and perhaps 4-bit grayscale images, and may well overtake CCITT 1D
  2159. and PackBits for bilevel images.
  2160.  
  2161.  
  2162. Future LZW Extensions
  2163.  
  2164. Some images compress better using LZW coding if they are first subjected to a
  2165. process wherein each pixel value is replaced by the difference between the pixel
  2166. and the preceding pixel.  Performing this differencing in two dimensions helps
  2167. some images even more.  However, many images do not compress better with this
  2168. extra preprocessing, and for a significant number of images, the compression
  2169. ratio is actually worse.  We are therefore not making differencing an integral
  2170. part of the TIFF LZW compression scheme.  
  2171.  
  2172. However, it is possible that a _prediction_ stage like differencing may exist
  2173. which is effective over a broad range of images.  If such a scheme is found, it
  2174. may be incorporated in the next major TIFF revision.  If so, a new value will be
  2175. defined for the new _Predictor_ TIFF tag.  Therefore, all TIFF readers that read
  2176. LZW files must pay attention to the Predictor tag.  If it is 1, which is the
  2177. default case, LZW decompression may proceed safely.  If it is not 1, and the
  2178. reader does not recognize the specified prediction scheme, the reader should give
  2179. up.
  2180.  
  2181.  
  2182. Acknowledgements
  2183.  
  2184. The original LZW reference has already been given.  The use of ClearCode as a
  2185. technique to handle overflow was borrowed from the compression scheme used by the
  2186. Graphics Interchange Format (GIF), a small-color-paint-image-file format used by
  2187. CompuServe that also is an adaptation of the LZW technique.  Joff Morgan and Eric
  2188. Robinson of Aldus were each instrumental in their own way in getting LZW off the
  2189. ground.
  2190.  
  2191. Appendix G: TIFF Classes
  2192.  
  2193.  
  2194. Rationale
  2195.  
  2196. TIFF was designed to make life easier for scanner vendors, desktop publishing
  2197. software developers, and users of these two classes of products, by reducing the
  2198. proliferation of proprietary scanned image formats.  It has succeeded far beyond
  2199. our expectations in this respect.  But we had expected that TIFF would be of
  2200. interest to only a dozen or so scanner vendors (there weren_t any more than that
  2201. in 1985), and another dozen or so desktop publishing software vendors.  This
  2202. turned out to be a gross underestimate.  The only problem with this sort of
  2203. success is that TIFF was designed to be powerful and flexible, at the expense of
  2204. simplicity.  It takes a fair amount of effort to handle all the options currently
  2205. defined in this specification (probably no application does a complete job), and
  2206. that is currently the only way you can be sure that you will be able to import
  2207. any TIFF image, since there are so many image-generating applications out there
  2208. now.
  2209.  
  2210. So here is an attempt to channel some of the flexibility of TIFF into more
  2211. restrictive paths, using what we have learned in the past two years about which
  2212. options are the most useful.  Such an undertaking is of course filled with fairly
  2213. arbitrary decisions.  But the result is that writers can more easily write files
  2214. that will be successfully read by a wide variety of applications, and readers can
  2215. know when they can stop adding TIFF features.
  2216.  
  2217. The price we pay for TIFF Classes is some loss in the ability to adapt.  Once we
  2218. establish the requirements for a TIFF Class, we can never add new requirements,
  2219. since old software would not know about these new requirements.  (The best we can
  2220. do at that point is establish new TIFF Classes.  But the problem with that is
  2221. that we could quickly have too many TIFF Classes.)  So we must believe that we
  2222. know what we are doing in establishing these Classes.  If we do not, any mistakes
  2223. will be expensive.
  2224.  
  2225.  
  2226. Overview
  2227.  
  2228. Four TIFF Classes have been defined:
  2229.  
  2230. —    Class B for bilevel (1-bit) images
  2231. —    Class G for grayscale images
  2232. —    Class P for palette color images
  2233. —    Class R for RGB full color images
  2234.  
  2235. To save time and space, we will usually say _TIFF B_, _TIFF G_, _TIFF P,_ and
  2236. _TIFF R._  If we are talking about all four types, we may write _TIFF X._
  2237.  
  2238. (Note to fax people:  if you are interested in a fax TIFF F Class, please get
  2239. together and decide what should be in TIFF Class F files.  Let us know if we can
  2240. help in any way.  When you have decided, send us your results, so that we can
  2241. include the information here.)
  2242.  
  2243.  
  2244. Core Requirements
  2245.  
  2246. This section describes requirements that are common to all TIFF Class X images.
  2247.  
  2248. General Requirements
  2249.  
  2250. The following are required characteristics of all TIFF Class X files.  
  2251.  
  2252. Where there are options, TIFF X writers can do whichever one they want, though we
  2253. will often recommend a particular choice, but TIFF X readers must be able to
  2254. handle all of them.  Please pay close attention to the recommendations.  It is
  2255. possible that at some point in the future, new and even-simpler TIFF classes will
  2256. be defined that include only recommended features.  
  2257.  
  2258. You will need to read at least the first three sections of the main specification
  2259. in order to fully understand the following discussion.
  2260.  
  2261. Defaults.  TIFF X writers may, but are not required, to write out a field that
  2262. has a default value, if the default value is the one desired.  TIFF X readers
  2263. must be prepared to handle either situation.
  2264.  
  2265. Other fields.  TIFF X readers must be prepared to encounter fields other than the
  2266. required fields in TIFF X files.  TIFF X writers are allowed to write fields such
  2267. as Make, Model, DateTime, and so on, and TIFF X readers can certainly make use of
  2268. such fields if they exist.  TIFF X readers must not, however, refuse to read the
  2269. file if such optional fields do not exist.
  2270.  
  2271. _MM_ and ëIIí byte order.  TIFF X readers must be able to handle both byte
  2272. orders.  TIFF writers can do whichever is most convenient or efficient.  Images
  2273. are crossing the IBM PC/Macintosh boundary (and others as well) with a
  2274. surprisingly high frequency.  We could force writers to all use the same byte
  2275. order, but preliminary evidence indicates that this will cause problems when we
  2276. start seeing greater-than-8-bit images.   Reversing bytes while scanning could
  2277. well slow down the scanning process enough to cause the scanning mechanism to
  2278. stop, which tends to create image quality problems.
  2279.  
  2280. Multiple subfiles.  TIFF X readers must be prepared for multiple images (i.e.,
  2281. subfiles) per TIFF file, although they are not required to do anything with any
  2282. image after the first one.  TIFF X writers must be sure to write a long word of 0
  2283. after the last IFD (this is the standard way of signalling that this IFD was the
  2284. last one) as indicated in the TIFF structure discussion.  
  2285.  
  2286. If a TIFF X writer writes multiple subfiles, the first one must be the full
  2287. resolution image.  Subsequent subimages, such as reduced resolution images and
  2288. transparency masks, may be in any order in the TIFF file.  If a reader wants to
  2289. make use of such subimages, it will have to scan the IFDís before deciding how to
  2290. proceed.
  2291.  
  2292. TIFF X Editors.  Editors, applications that modify TIFF files, have a few
  2293. additional requirements.
  2294.  
  2295. TIFF editors must be especially careful about subfiles.  If a TIFF editor edits a
  2296. full-resolution subfile, but does not update an accompanying reduced-resolution
  2297. subfile, a reader that uses the reduced-resolution subfile for screen display
  2298. will display the wrong thing.  So TIFF editors must either create a new
  2299. reduced-resolution subfile when they alter a full-resolution subfile, or else
  2300. they must simply delete any subfiles that they aren_t prepared to deal with.
  2301.  
  2302. A similar situation arises with the fields themselves.  A TIFF X editor need only
  2303. worry about the TIFF X required fields.  In particular, it is unnecessary, and
  2304. probably dangerous, for an editor to copy fields that it does not understand.  It
  2305. may have altered the file in a way that is incompatible with the unknown fields.
  2306.  
  2307.  
  2308. Required Fields
  2309.  
  2310. NewSubfileType.  LONG.  Recommended but not required.
  2311.  
  2312. ImageWidth.  SHORT or LONG.  (That is, both _SHORT_ and _LONG_ TIFF data types
  2313. are allowed, and must be handled properly by readers.  TIFF writers can use
  2314. either.)  TIFF X readers are not required to read arbitrarily large files
  2315. however.  Some readers will give up if the entire image cannot fit in available
  2316. memory.  (In such cases the reader should inform the user of the nature of the
  2317. problem.)  Others will probably not be able to handle ImageWidth greater than
  2318. 65535.  Recommendation: use LONG, since resolutions seem to keep going up.
  2319.  
  2320. ImageLength.  SHORT or LONG.  Recommendation: use  LONG.
  2321.  
  2322. RowsPerStrip.  SHORT or LONG.  Readers must be able to handle any value between 1
  2323. and 2**32-1.  However, some readers may try to read an entire strip into memory
  2324. at one time, so that if the entire image is one strip, the application may run
  2325. out of memory.  Recommendation 1:  Set RowsPerStrip such that the size of each
  2326. strip is about 8K bytes.  Do this even for uncompressed data, since it is easy
  2327. for a writer and makes things simpler for readers.  (Note:  extremely wide,
  2328. high-resolution images may have rows larger than 8K bytes; in this case,
  2329. RowsPerStrip should be 1, and the strip will just have to be larger than 8K. 
  2330. Recommendation 2: use LONG.
  2331.  
  2332. StripOffsets.  SHORT or LONG.  As explained in the main part of the
  2333. specification, the number of StripOffsets depends on RowsPerStrip and
  2334. ImageLength.  Recommendation:  always use LONG.  (LONG must, of course, be used
  2335. if the file is more than 64K bytes in length.)
  2336.  
  2337. StripByteCounts.  SHORT or LONG.  Many existing TIFF images do not contain
  2338. StripByteCounts, because, in a strict sense, they are unnecessary.  It is
  2339. possible to write an efficient TIFF reader that does not need to know in advance
  2340. the exact size of a compressed strip.  But it does make things considerably more
  2341. complicated, so we will require StripByteCounts in TIFF X files.  Recommendation:
  2342.  use SHORT, since strips are not supposed to be very large.
  2343.  
  2344. XResolution, YResolution.  RATIONAL.  Note that the X and Y resolutions may be
  2345. unequal.  A TIFF X reader must be able to handle this case.  TIFF X pixel-editors
  2346. will typically not care about the resolution, but applications such as page
  2347. layout programs will.
  2348.  
  2349. ResolutionUnit.  SHORT.  TIFF X readers must be prepared to handle all three
  2350. values for ResolutionUnit.
  2351.  
  2352.  
  2353. TIFF Class B - Bilevel
  2354.  
  2355. Required (in addition to the above core requirements)
  2356.  
  2357. The following fields and values are required for TIFF B files, in addition to the
  2358. fields required for all TIFF X images (see above).
  2359.  
  2360. SamplesPerPixel = 1.  SHORT.  (Since this is the default, the field need not be
  2361. present.  The same thing holds for other required TIFF X fields that have
  2362. defaults.)
  2363.  
  2364. BitsPerSample = 1.  SHORT.  
  2365.  
  2366. Compression = 1, 2 (CCITT 1D), or 32773 (PackBits).  SHORT.  TIFF B readers must
  2367. handle all three.  Recommendation:  use PackBits.  It is simple, effective, fast,
  2368. and has a good worst-case behavior.  CCITT 1D is definitely more effective in
  2369. some situations, such as scanning a page of body text, but is tough to implement
  2370. and test, fairly slow, and has a poor worst-case behavior.  Besides, scanning a
  2371. page of 12 point text is not very useful for publishing applications, unless the
  2372. image data is turned into ASCII text via OCR software, which is outside the scope
  2373. of TIFF.
  2374.  
  2375. PhotometricInterpretation = 0 or 1.  SHORT.
  2376. A Sample TIFF B Image
  2377.  
  2378. Offset         Value
  2379. (hex)    Name    (mostly hex)
  2380.  
  2381. Header:
  2382. 0000    Byte Order    4D4D
  2383. 0002    Version    002A
  2384. 0004    1st IFD pointer    00000014
  2385.  
  2386. IFD:
  2387. 0014    Entry Count    000D
  2388. 0016    NewSubfileType    00FE    0004    00000001    00000000
  2389. 0022    ImageWidth    0100    0004    00000001    000007D0
  2390. 002E    ImageLength    0101    0004    00000001    00000BB8
  2391. 003A    Compression    0103    0003    00000001    8005 0000
  2392. 0046    PhotometricInterpretation    0106    0003    00000001    0001 0000
  2393. 0052    StripOffsets    0111    0004    000000BC    000000B6
  2394. 005E    RowsPerStrip    0116    0004    00000001    00000010
  2395. 006A    StripByteCounts    0117    0003    000000BC    000003A6
  2396. 0076    XResolution    011A    0005    00000001    00000696
  2397. 0082    YResolution    011B    0005    00000001    0000069E
  2398. 008E    Software    0131    0002    0000000E    000006A6
  2399. 009A    DateTime    0132    0002    00000014    000006B6
  2400. 00A6    Next IFD pointer    00000000
  2401.  
  2402. Fields pointed to by the tags:
  2403. 00B6    StripOffsets    Offset0, Offset1, ... Offset187
  2404. 03A6    StripByteCounts    Count0, Count1, ... Count187
  2405. 0696    XResolution    0000012C 00000001
  2406. 069E    YResolution    0000012C 00000001
  2407. 06A6    Software    "PageMaker 3.0"
  2408. 06B6    DateTime    "1988:02:18 13:59:59"
  2409.  
  2410.  
  2411. Image Data:
  2412. 00000700    Compressed data for strip 10
  2413. xxxxxxxx     Compressed data for strip 179
  2414. xxxxxxxx    Compressed data for strip 53
  2415. xxxxxxxx    Compressed data for strip 160
  2416. .
  2417. .
  2418. .
  2419.  
  2420. End of example
  2421.  
  2422. Comments on the TIFF B example
  2423.  
  2424. 1.    The IFD in our example starts at position hex 14.  It could have been
  2425. anywhere in the file as long as the position is even and greater than or equal to
  2426. 8, since the TIFF header is 8 bytes long and must be the first thing in a TIFF
  2427. file.
  2428.  
  2429. 2.    With 16 rows per strip, we have 188 strips in all.
  2430.  
  2431. 3.    The example uses a number of optional fields, such as DateTime.  TIFF X
  2432. readers must safely skip over these fields if they do not want to use the
  2433. information.  And TIFF X readers must not require that such fields be present.
  2434.  
  2435. 4.    Just for fun, our example has highly fragmented image data; the strips of
  2436. our image are not even in sequential order.  The point is that strip offsets must
  2437. not be ignored.  Never assume that strip N+1 follows strip N.  Incidentally,
  2438. there is no requirement that the image data follows the IFD information.  Just
  2439. the follow the pointers, whether they be IFD pointers, field pointers, or Strip
  2440. Offsets.
  2441.  
  2442.  
  2443.  
  2444. TIFF Class G - Grayscale
  2445.  
  2446. Required (in addition to the above core requirements)
  2447.  
  2448. SamplesPerPixel = 1.  SHORT.
  2449.  
  2450. BitsPerSample = 4, 8.  SHORT.  There seems to be little justification for working
  2451. with grayscale images shallower than 4 bits, and 5-bit , 6-bit, and 7-bit images
  2452. can easily be stored as 8-bit images, as long as you can compress the _unused_
  2453. bit planes without penalty.  And we can do just that with LZW (Compression = 5.)
  2454.  
  2455. Compression = 1 or 5 (LZW).  SHORT.  Recommendation: use 5, since LZW
  2456. decompression is turning out to be quite fast.
  2457.  
  2458. PhotometricInterpretation = 0 or 1.  SHORT.   Recommendation: use 1, due to
  2459. popular user interfaces for adjusting brightness and contrast.
  2460.  
  2461.  
  2462.  
  2463. TIFF Class P - Palette Color
  2464.  
  2465. Required (in addition to the above core requirements)
  2466.  
  2467. SamplesPerPixel = 1.  SHORT.  We use each pixel value as an index into all three
  2468. color tables in ColorMap.
  2469.  
  2470. BitsPerSample = 1,2,3,4,5,6,7, or 8.  SHORT.  1,2,3,4, and 8 are probably the
  2471. most common, but as long as we are doing that, the rest come pretty much for
  2472. free.
  2473.  
  2474. Compression = 1 or 5.  SHORT.  
  2475.  
  2476. PhotometricInterpretation = 3 (Palette Color).  SHORT.
  2477.  
  2478. ColorMap.  SHORT.
  2479.  
  2480. Note that bilevel and grayscale images can be represented as special cases of
  2481. palette color images.  As soon as enough major applications support palette color
  2482. images, we may want to start getting rid of distinctions between bilevel,
  2483. grayscale, and palette color images.
  2484.  
  2485.  
  2486. TIFF Class R - RGB Full Color
  2487.  
  2488. Required (in addition to the above Core Requirements)
  2489.  
  2490. SamplesPerPixel = 3.  SHORT.  One sample each for Red, Green, and Blue.
  2491.  
  2492. BitsPerSample = 8,8,8.  SHORT.  Shallower samples can easily be stored as 8-bit
  2493. samples with no penalty if the data is compressed with LZW.  And evidence to date
  2494. indicates that images deeper than 8 bits per sample are not worth the extra work,
  2495. even in the most demanding publishing applications.
  2496.  
  2497. PlanarConfiguration = 1 or 2.  SHORT.  Recommendation:  use 1.
  2498.  
  2499. Compression = 1 or 5.  SHORT.  
  2500.  
  2501. PhotometricInterpretation = 2 (RGB).  SHORT.
  2502.  
  2503. Recommended
  2504.  
  2505. Recommended for TIFF Class R, but not required, are the new (as of Revision 5.0)
  2506. colorimetric information tags.  See Appendix H.
  2507.  
  2508.  
  2509. Conformance and User Interface
  2510.  
  2511. Applications that write valid TIFF X files should include _TIFF B_ and/or _TIFF
  2512. G_ and/or _TIFF P_ and/or _TIFF R_ and/or in their product spec sheets, if they
  2513. can write the respective TIFF Class X files.  If your application writes all four
  2514. of these types, you may wish to write it as _TIFF B,G,P,R._  Of course, a term
  2515. like _TIFF B,_ while fine for communicating with other vendors, will not convey
  2516. much information to a typical user.  In this case, a phrase such as _Standard
  2517. TIFF Black-and-White Scanned Images_ might be better.
  2518.  
  2519. The same terminology guidelines apply to applications that read TIFF Class X
  2520. files.
  2521.  
  2522. If your application reads more kinds of files than it writes, or vice versa, it
  2523. would be a good idea to make that clear to the buyer.  For example, if your
  2524. application reads TIFF B and TIFF G files, but writes only TIFF G files, you
  2525. should write it that way in the spec sheet.
  2526.  
  2527. Appendix H: Image Colorimetry Information
  2528.  
  2529. Chris Sears
  2530. 210 Lake Street
  2531. San Francisco, CA 94118
  2532.  
  2533. June 4, 1988
  2534. Revised August 8, 1988
  2535.  
  2536.  
  2537. I. Introduction
  2538.  
  2539. Our goal is to accurately reproduce a color image using different devices. 
  2540. Accuracy requires techniques of measurement and a standard of comparison. 
  2541. Different devices imply device independence.  Colorimetry provides the framework
  2542. to solve these problems.  When an image has a complete colorimetric description,
  2543. in principle it can be reproduced identically on different monitors and using
  2544. different media, such as offset lithography.
  2545.  
  2546. The colorimetry data is specified when the image is created or changed.  A
  2547. scanned image has colorimetry data derived from  the filters and light sources of
  2548. the scanner and a synthetic image has colorimetry data corresponding to the
  2549. monitor used to create it or the monitor model of the rendering environment. 
  2550. This data is used to map an input image to the markings or colors of a particular
  2551. output device.
  2552.  
  2553. Section II describes various standards organizations and their work in color.
  2554. Section III describes our motivation for seeking these tags.
  2555. Section IV describes our goals of reproduction.
  2556. Sections V, VI and VII introduce the colorimetry tags.
  2557. Section VIII specifies the tags themselves.
  2558. Section IX describes the defaults.
  2559. Section X discusses the limitations and some of the other issues.
  2560. Section XI provides a few references.
  2561.  
  2562.  
  2563. II. Related Standards
  2564.  
  2565. TIFF is a general standard for describing image data.  It would be foolish for us
  2566. to change TIFF in a way that did not match existing industry and international
  2567. standards.  Therefore, we have taken pains to note in the discussion below the
  2568. efforts of various standards organizations and select defaults from the work of
  2569. these organizations.
  2570.  
  2571. CIE    (Commission Internationale de líEclairage)  The basis of the colorimetry
  2572. information is the CIE 1931 Standard Observer [3].  While other color models
  2573. could be supported [1] [4], CIE 1931 XYZ is the international standard accepted
  2574. across industries for specifying color and CIE xyY is the chromaticity diagram
  2575. associated with CIE 1931 XYZ tristimulus values.
  2576.  
  2577. NTSC    (National Television System Committee)  NTSC is of interest primarily for
  2578. historical reasons and its use in encoding television data.  Manufacturing
  2579. standards for monitors have for some time drifted significantly from the 1953
  2580. NTSC colorimetry specification.
  2581.  
  2582. SMPTE    (Society of Motion Picture and Television Engineers)   Most of the work
  2583. by NTSC has been largely subsumed by SMPTE.  This organization has a set of
  2584. standards called "Recommended Practices" that apply to various technical aspects
  2585. of film and television production [5] [6].
  2586.  
  2587. ISO    (International Standards Organization)  ISO has become involved in color
  2588. standards through work on a color addendum to "Office Document Architecture (ODA)
  2589. and Interchange Format" [7].
  2590.  
  2591. ANSI    (American National Standards Institute)  ANSI is the American
  2592. representative to ISO .
  2593.  
  2594.  
  2595. III. Motivation
  2596.  
  2597. Our motivation for defining these tags stems from our research and development in
  2598. color separation technology.  With the information described here and the RGB
  2599. pixel data, we have all of the information necessary for generating high-quality
  2600. color separations.  We could supply the colorimetry information outside of the
  2601. image file.  But since TIFF provides a convenient mechanism for bundling all of
  2602. the relevant information in a single place, tags are defined to describe this
  2603. information in color TIFF files.
  2604.  
  2605. A color image rendered with incorrect colorimetry information looks different
  2606. from the original.  One of our early test images has an artifact in it where the
  2607. image was scanned with one set of primaries and color ramps were overlaid on top
  2608. of it with different primaries.  The blue ramp looked purple when we printed it.
  2609. Using incorrect gamma tables or white points can also lead to distorted images. 
  2610. The best way to avoid these kinds of errors is to allow the creator of an image
  2611. to supply the colorimetry information along with the RGB values [1] [2].
  2612.  
  2613. The purpose of the colorimetry data is to allow a projective transformation from
  2614. the primaries and white point of the image to the primaries and white point of
  2615. the rendering media.  Gamma reflects the non-linear transfer gradient of real
  2616. media.
  2617.  
  2618.  
  2619. IV. Colorimetric Color Reproduction
  2620.  
  2621. Earlier we said that given the proper colorimetric data an image could be
  2622. rendered identically using two different calibrated devices.  By identical, we
  2623. mean colorimetric reproduction [9].  Specifically, the chromaticities match and
  2624. the luminance is scaled to correspond to the luminance range of the output
  2625. device.  Because of this, we only need the chromaticity coordinates of the white
  2626. point and primaries.  The absolute luminance is arbitrary and unnecessary.
  2627.  
  2628.  
  2629. V. White Point
  2630.  
  2631. In TIFF 4.0, the white point was specified as D65.  This appendix allocates a
  2632. separate tag for describing the white point and D65 is the logical default since
  2633. it is the SMPTE standard [6].
  2634.  
  2635. The white point is defined colorimetrically in the CIE xyY chromaticity diagram. 
  2636. While it is rare for monitors to differ from D65, scanned images often have
  2637. different white points.  Rendered images can have arbitrary white points.  The
  2638. graphic arts use D50 as the standard viewing light source [8].
  2639.  
  2640.  
  2641. VI. Primary Chromaticities
  2642.  
  2643. In TIFF 4.0, the primary color chromaticities matched the NTSC specification. 
  2644. With the wide variety of color scanners, monitors and renderers, TIFF needs a
  2645. mechanism for accurately describing the chromaticities of the primary colors.  We
  2646. use SMPTE as the default chromaticity since conventional monitors are closer to
  2647. SMPTE and some monitors (Conrac 6545) are manufactured to the SMPTE
  2648. specifications.  We donít use the NTSC chromaticities and white point because
  2649. present day monitors donít use them and must be _matrixed_ to approximate them.
  2650.  
  2651. As an example, the primary color chromaticities used by the Sony Trinatron differ
  2652. from those recommended by SMPTE.  In general, since real monitors vary from the
  2653. industry standards, the chromaticities of primaries are described in the CIE xyY
  2654. system.  This allows a reproduction system to compensate for the differences.
  2655.  
  2656.  
  2657. VII. Color Response Curves
  2658.  
  2659. This tag defines three color response curves, one each for red, green, and blue
  2660. color information.  The width of each entry is 16 bits, as implied by the type
  2661. SHORT.  The minimum intensity is represented by 0 and the maximum by 65535.  For
  2662. example, black is represented by 0,0,0 and white by 65535, 65535, 65535.  The
  2663. length of each curve is 2**BitsPerSample.  A ColorResponseCurves field for RGB
  2664. data where each of the samples is 8 bits deep would have 3*256 entries.  The 256
  2665. red entries would come first, followed by 256 green entries, followed by 256 blue
  2666. entries.
  2667.  
  2668. The purpose of the ColorResponseCurves field is to act as a lookup table mapping
  2669. sample values to specific intensity values, so that an image created on one
  2670. system can be displayed on another with minimal loss of color fidelity.  The
  2671. ColorResponseCurves field thus describes the _gamma_ of an image, so that a TIFF
  2672. reader on another system can compensate for both the image gamma and the gamma of
  2673. the reading system.
  2674.  
  2675. Gamma is a term that relates to the typically nonlinear response of most display
  2676. devices, including monitors.  In most display systems, the voltage applied to the
  2677. CRT is directly proportional to the value of the red, green, or blue sample. 
  2678. However, the resulting luminance emitted by the phosphor is not directly
  2679. proportional to the voltage.  This relationship is approximated in most displays
  2680. by
  2681.  
  2682.     luminance = voltage ** gamma
  2683.  
  2684. The NTSC standard gamma of 2.2 adequately describes most common video systems.
  2685. The standard gamma of 2.2 implies a dim viewing surround.  (We know of no SMPTE
  2686. recommended practice for gamma.)  The following example uses an 8 bit sample with
  2687. value of 127.
  2688.  
  2689.     voltage = 127 / 255 = 0.4980
  2690.     luminance = 0.4980 ** 2.2 = 0.2157
  2691.  
  2692. In the examples below, we only consider a single primary and therefore only a
  2693. single curve.  The same analysis applies to each of the red, green, and blue
  2694. primaries and curves.  Also, and without loss of generality, we assume that there
  2695. is no hardware color map, so that we must alter the pixel values themselves.  If
  2696. there is a color map, the manipulations can be done on the map instead of on the
  2697. pixels.
  2698.  
  2699. If no ColorResponseCurves field exists in a color image, the reader should assume
  2700. a gamma of 2.2 for each of the primaries.  This default curve can be generated
  2701. with the following C code:
  2702.  
  2703.     ValuesPerSample = 1 << BitsPerSample;
  2704.     for (curve[0] = 0, i = 1; i < ValuesPerSample; i++)
  2705.         curve[i] = floor (pow (i / (ValuesPerSample - 1.0), 2.2) * 65535.0 + .5);
  2706.  
  2707. The displaying or rendering application can know its own gamma, which we will
  2708. call the _destination gamma._  (An uncalibrated system can usually assume that
  2709. its gamma is 2.2 without going too far wrong.)  Using this information the
  2710. application can compensate for the gamma of the image, as we shall see below.
  2711.  
  2712. If the source and destination systems are both adequately described by a gamma of
  2713. 2.2, the writer would omit the ColorResponseCurves field, and the reader can
  2714. simply read the image directly into the frame buffer.  If a writer writes out the
  2715. ColorResponseCurves field, then a reader must assume that the gammas differ.  A
  2716. reader must then perform the following computation on each sample in the image:
  2717.  
  2718.     NewSampleValue = floor (pow (curve[OldSampleValue] / 65535.0, 1.0 /
  2719. DestinationGamma) * 
  2720.       (ValuesPerSample - 1.0) + .5);
  2721.  
  2722. Of course, if the _gamma_ of the destination system is not well-approximated with
  2723. an exponential function, an arbitrary table lookup may be used in place of
  2724. raising the value to 1.0 / DestinationGamma.
  2725.  
  2726. Leave out ColorResponseCurves if using the default gamma.  This saves about 1.5K
  2727. in the most common case, and, after all, omission is the better part of
  2728. compression.
  2729.  
  2730. Do not use this field to store frame buffer color maps.  Use instead the ColorMap
  2731. field.  Note, however, that ColorResponseCurves may be used to refine the
  2732. information in a ColorMap if desired.
  2733.  
  2734. The above examples assume that a single parameter gamma system adequately
  2735. approximates the response characteristics of the image source and destination
  2736. systems.  This will usually be true, but our use of a table instead of a single
  2737. gamma parameter gives the flexibility to describe more complex relationships,
  2738. without requiring additional computation or complexity.
  2739.  
  2740.  
  2741. VIII. New Tags and Changes
  2742. The following tags should be placed in the "Basic Fields" section of
  2743. the TIFF specification:
  2744.  
  2745. White Point
  2746. Tag    = 318 (13E)
  2747. Type    = RATIONAL
  2748. N    = 2
  2749.  
  2750. The white point of the image.  Note that this value is described using the 1931
  2751. CIE xyY chromaticity diagram and only the chromaticity is specified.  The
  2752. luminance component is arbitrary and not specified.  This can correspond to the
  2753. white point of a monitor that the image was painted on, the filter set/light
  2754. source combination of a scanner, or to the white point of the illumination model
  2755. of a rendering package.
  2756.  
  2757. Default is the SMPTE white point, D65:  x = 0.313, y = 0.329.
  2758.  
  2759. The ordering is x, y.
  2760.  
  2761.  
  2762. PrimaryChromaticities
  2763. Tag    = 319 (13F)
  2764. Type    = RATIONAL
  2765. N    = 6
  2766.  
  2767. The primary color chromaticities.  Note that these values are described using the
  2768. 1931 CIE xyY chromaticity diagram and only the chromaticities are specified.  For
  2769. paint images, these represent the chromaticities of the monitor and for scanned
  2770. images they are derived from the filter set/light source combination of a
  2771. scanner.
  2772.  
  2773. Default is the SMPTE primary color chromaticities:
  2774.  
  2775.     Red:    x = 0.635    y = 0.340
  2776.     Green:    x = 0.305    y = 0.595
  2777.     Blue:    x = 0.155    y = 0.070
  2778.  
  2779. The ordering is red x, red y, green x, green y, blue x, blue y.
  2780.  
  2781. Color Response Curves
  2782.  
  2783. Default for ColorResponseCurves represents curves corresponding to the NTSC
  2784. standard gamma of 2.2.
  2785.  
  2786.  
  2787. IX. Defaults
  2788.  
  2789. The defaults used by TIFF reflect industry standards.  Both the WhitePoint and
  2790. PrimaryChromaticities tags have defaults that are promoted by SMPTE .  In
  2791. addition, the default for the ColorResponseCurves tag matches the NTSC
  2792. specification of a gamma of 2.2.
  2793.  
  2794. The purpose of these defaults is to allow reasonable results in the absence of
  2795. accurate colorimetry data.  An uncalibrated scanner or paint system produces an
  2796. image that be displayed identically, though probably incorrectly on two different
  2797. but calibrated systems.  This is better then the uncertain situation where the
  2798. image might be rendered differently on two different but calibrated systems.
  2799.  
  2800.  
  2801. X. Limitations and Issues
  2802.  
  2803. This section discusses several of the limitations and issues involved in
  2804. colorimetric reproduction.
  2805.  
  2806. Scope of Usefulness
  2807.  
  2808. For many purposes the data recommended here is unnecessary and can be omitted. 
  2809. For presentation graphics where there are only a few colors, being able to tell
  2810. red from green is probably good enough.  In this case the tags can be ignored and
  2811. there is no overhead.  In more demanding color reproduction environments, this
  2812. data allows images to be described device independently and at small cost.
  2813.  
  2814. User Burdens
  2815.  
  2816. The data we recommend isnít a user burden; it is really a systems issue.  It
  2817. allows a systems solution but doesnít require user intercession.  Calibration
  2818. however is a separate issue.  It is likely to involve the user.
  2819.  
  2820. Resolution Versus Fidelity
  2821.  
  2822. Some manufacturers supply greater than 24 bits of resolution for color
  2823. specification.  The purpose of this is either to avoid artifacts such as
  2824. contouring in the shadows or in some cases to be more specific or device
  2825. independent about the color.  Both reasons can be misguided.  Other, less
  2826. expensive techniques can be used to prevent artifacts, such as deeper color maps.
  2827.  As for accuracy, fidelity is more important than precision.
  2828.  
  2829. Colorimetric Color Reproduction
  2830.  
  2831. There are other choices for objectives of color reproduction [9].  Spectral color
  2832. reproduction is a stronger condition and most are weaker, such as preferred color
  2833. reproduction.  While device independent spectral color reproduction is
  2834. impossible, device independent colorimetric reproduction is possible, within a
  2835. tolerance and within the limits of the gamuts of the devices.  By choosing a
  2836. strong criteria we allow the important objectives of weaker criteria, such as
  2837. preferred color reproduction, to be part of design packages.
  2838.  
  2839. Metamerism
  2840.  
  2841. If two patches of color are identical under one light and different under
  2842. another, they are said to be metameric pairs.  Colorimetric color reproduction is
  2843. a weaker condition than spectral color reproduction and hence allows metamerism
  2844. problems.  By standardizing the viewing conditions we can largely finesse the
  2845. metamerism problem for print.  Because television is self-luminous and doesnít
  2846. use spectral absorption, metamerism isnít so much a problem.
  2847.  
  2848. Color Models - xyY Versus Luv, etc.
  2849.  
  2850. We choose xyY over Luv [1] because XYZ is the international standard for color
  2851. specification and xyY is the chromaticity diagram associated with XYZ.  Luv is
  2852. meant for color difference measurement.
  2853.  
  2854. Ambient Environment And Viewing Surrounds
  2855.  
  2856. The viewing environment affects how the eye perceives color.  The eye adapts to a
  2857. dark room and it adapts to a colored surround.  While these problems can be
  2858. compensated for within the colorimetric framework [4], it is much better to
  2859. finesse them by standardizing.  The design environment should match the intended
  2860. viewing environment.  Specifically it should not be a pitch dark room and, on
  2861. average, it should be of a neutral color.  For print, ANSI recommends a Munsell
  2862. N-8 surface [8].
  2863.  
  2864.  
  2865. XI. References
  2866.  
  2867. In particular, we would like to mention the work of Stuart Ring of the Copy
  2868. Products Division of the Eastman Kodak Company.  He and his colleagues are
  2869. promoting a color data interchange paradigm.  They are working closely with the
  2870. ISO 8613 Working Group [7].
  2871.  
  2872. [1]    Color Data Interchange Paradigm, Eastman Kodak, Rochester, New York, 7
  2873. December 1987.
  2874.  
  2875. [2]    Color Reproduction and Illumination Models, Roy Hall, International Summer
  2876. Institute:  State of the Art in Computer Graphics, 1986.
  2877.  
  2878. [3]    CIE Colorimetry: Official Recommendations of the International Commission
  2879. on Illumination, Publication 15-2, 1986.
  2880.  
  2881. [4]    Color Science: Concepts and Methods, Quantitative Data and Formulae,
  2882. Gunter Wyszecki, W.S. Stiles, John Wiley and Sons, Inc., New York, New York,
  2883. 1982.
  2884.  
  2885. [5]    Color Monitor Colorimetry, SMPTE Recommended Practice RP 145-1987.
  2886.  
  2887. [6]    Color Temperature for Color Television Studio Monitors, SMPTE Recommended
  2888. Practice RP 37.
  2889.  
  2890. [7]    Office Document Architecture (ODA) and Interchange Format_Addendum on
  2891. Colour, ISO 8613 Working Draft.
  2892.  
  2893. [8]    ANSI Standard PH 2.30-1985.
  2894.  
  2895. [9]    The Reproduction of Colour in Photography, Printing and Television, R. W.
  2896. G. Hunt, Fountain Press, Tolworth, England, 1987.
  2897.  
  2898. [10]    Raster Graphics Handbook, The Conrac Corporation, Van Nostrand Reinhold
  2899. Company, New York, New York, 1985.  Good description of gamma.
  2900.  
  2901.  
  2902.  
  2903. Appendix I:  Horizontal Differencing Predictor
  2904.  
  2905.  
  2906. This appendix, written after the release of Revision 5.0 of the TIFF
  2907. specification, is still in draft form.  Please send any comments to the Aldus
  2908. Developers Desk.
  2909.  
  2910.  
  2911. Revision 5.0 of the TIFF specification defined a new tag called _Predictor_ that
  2912. describes techniques that may be used in conjuction with TIFF compression
  2913. schemes.  We now define a Predictor that greatly improves compression ratios for
  2914. some images.
  2915.  
  2916. The horizontal differencing predictor is assigned the tag value Predictor = 2:
  2917.  
  2918. Predictor
  2919. Tag    = 317 (13D)
  2920. Type    = SHORT
  2921. N    = 1
  2922.  
  2923. A predictor a mathematical operator that is applied to the image data before the
  2924. encoding scheme is applied.  Currently (as of revision 5.0) this tag is used only
  2925. with LZW (Compression=5) encoding, since LZW is probably the only TIFF encoding
  2926. scheme that benefits significantly from a predictor step.  See Appendix F.
  2927.  
  2928. 1 = No prediction scheme used before coding.
  2929. 2 = Horizontal differencing. See Appendix I.
  2930.  
  2931. Default is 1.
  2932.  
  2933.  
  2934. The algorithm
  2935.  
  2936. The idea is to make use of the fact that many continuous tone images rarely vary
  2937. much in pixel value from one pixel to the next.  In such images, if we replace
  2938. the pixel values by differences between consecutive pixels, many of the
  2939. differences should be 0, plus or minus 1, and so on.  This reduces the apparent
  2940. information content, and thus allows LZW to encode the data more compactly.
  2941.  
  2942. Assuming 8-bit grayscale pixels for the moment, a basic C implementation might
  2943. look something like this:
  2944.  
  2945.     char    image[ ][ ];
  2946.     int    row, col;
  2947.  
  2948.     /* take horizontal differences:
  2949.      */
  2950.     for (row = 0; row < nrows; row++)
  2951.         for (col = ncols - 1; col >= 1; col--)
  2952.             image[row][col] -= image[row][col-1];
  2953.  
  2954. If we don_t have 8-bit samples, we need to work a little harder, so that we can
  2955. make better use of the architecture of most CPUs.  Suppose we have 4-bit samples,
  2956. packed two to a byte, in normal TIFF uncompressed (i.e., Compression=1) fashion. 
  2957. In order to find differences, we want to first expand each 4-bit sample into an
  2958. 8-bit byte, so that we have one sample per byte, low-order justified.  We then
  2959. perform the above horizontal differencing.  Once the differencing has been
  2960. completed, we then repack the 4-bit differences two to a byte, in normal TIFF
  2961. uncompressed fashion.
  2962.  
  2963. If the samples are greater than 8 bits deep, expanding the samples into 16-bit
  2964. words instead of 8-bit bytes seems like the best way to perform the subtraction
  2965. on most computers.
  2966.  
  2967. Note that we have not lost any data up to this point, nor will we lose any data
  2968. later on.  It might at first seem that our differencing might turn 8-bit samples
  2969. into 9-bit differences, 4-bit samples into 5-bit differences, and so on.  But it
  2970. turns out that we can completely ignore the _overflow_ bits caused by subtracting
  2971. a larger number from a smaller number and still reverse the process without
  2972. error.  Normal twos complement arithmetic does just what we want.  Try an example
  2973. by hand if you need more convincing.
  2974.  
  2975. Up to this point we have implicitly assumed that we are compressing bilevel or
  2976. grayscale images.  An additional consideration arises in the case of color
  2977. images.
  2978.  
  2979. If PlanarConfiguration is 2, there is no problem.  Differencing proceeds the same
  2980. way as it would for grayscale data.
  2981.  
  2982. If PlanarConfiguration is 1, however, things get a little trickier.  If we didnít
  2983. do anything special, we would be subtracting red sample values from green sample
  2984. values, green sample values from blue sample values, and blue sample values from
  2985. red sample values, which would not give the LZW coding stage much redundancy to
  2986. work with.  So we will do our horizontal differences with an offset of
  2987. SamplesPerPixel (3, in the RGB case).  In other words, we will subtract red from
  2988. red, green from green, and blue from blue.  The LZW coding stage is identical to
  2989. the SamplesPerPixel=1 case.  We require that BitsPerSample be the same for all 3
  2990. samples.
  2991.  
  2992.  
  2993. Results and guidelines
  2994.  
  2995. LZW without differencing works well for 1-bit images, 4-bit grayscale images, and
  2996. synthetic color images.  But natural 24-bit color images and some 8-bit grayscale
  2997. images do much better with differencing.  For example, our 24-bit natural test
  2998. images hardly compressed at all using _plain_ LZW: the average compression ratio
  2999. was 1.04 to 1.  The average compression ratio with horizontal differencing was
  3000. 1.40 to 1.  (A compression ratio of 1.40 to 1 means that if the uncompressed
  3001. image is 1.40MB in size, the compressed version is 1MB in size.)
  3002.  
  3003. Although the combination of LZW coding with horizontal differencing does not
  3004. result in any loss of data, it may be worthwhile in some situations to give up
  3005. some information by removing as much noise as possible from the image data before
  3006. doing the differencing, especially with 8-bit samples.  The simplest way to get
  3007. rid of noise is to mask off one or two low-order bits of each 8-bit sample.  On
  3008. our 24-bit test images, LZW with horizontal differencing yielded an average
  3009. compression ratio of 1.4 to 1.  When the low-order bit was masked from each
  3010. sample, the compression ratio climbed to 1.8 to 1; the compression ratio was 2.4
  3011. to 1 when masking two bits, and 3.4 to 1 when masking three bits.  Of course, the
  3012. more you mask, the more you risk losing useful information along with the noise. 
  3013. We encourage you to experiment to find the best compromise for your device.  For
  3014. some applications it may be useful to let the user make the final decision.
  3015.  
  3016. Interestingly, most of our RGB images compressed slightly better using
  3017. PlanarConfiguration=1.  One might think that compressing the red, green, and blue
  3018. difference planes separately (PlanarConfiguration=2) might give better
  3019. compression results than mixing the differences together before compressing
  3020. (PlanarConfiguration=1), but this does not appear to be the case.
  3021.  
  3022. Incidentally, we tried taking both horizontal and vertical differences, but the
  3023. extra complexity of two-dimensional differencing did not appear to pay off for
  3024. most of our test images.  About one third of the images compressed slightly
  3025. better with two-dimensional differencing, about one third compressed slightly
  3026. worse, and the rest were about the same.
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032. Appendix J:  Palette Color
  3033.  
  3034.  
  3035. This appendix, written after the release of Revision 5.0 of the TIFF
  3036. specification, is still in draft form.  Please send any comments to the Aldus
  3037. Developers Desk.
  3038.  
  3039.  
  3040. Revision 5.0 of the TIFF specification defined a new PhotometricInterpretation
  3041. value called _palette color._  We have been wondering lately if this additional
  3042. complexity is worth the implementation expense.  If not, let_s drop it before too
  3043. many people start creating palette color images.
  3044.  
  3045.  
  3046. The Proposal
  3047.  
  3048. Instead of a separate palette color image type, there seems to be no compelling
  3049. reason why palette (mapped) color images should not be stored as _full color_
  3050. (usually 24-bit) RGB images.
  3051.  
  3052.  
  3053. Objections
  3054.  
  3055. The most obvious objection is the amount of space required.  But if you care
  3056. about how much space the image takes up on disk, you should use LZW compression,
  3057. which is ideally suited to most palette color images.  (LZW compresses most
  3058. paint-type palette color images 5:1 or more.)  And if you use LZW compression, it
  3059. turns out that palette color images stored as full color images compress to
  3060. almost exactly the same size as palette color images stored as palette color
  3061. images.  That is, with LZW compression, there is no penalty for storing palette
  3062. color images as full color RGB images.  The resulting file may be a few percent
  3063. larger, but it will not be three times as large.  See Appendix F for more
  3064. information on how LZW works.
  3065.  
  3066. Another objection might be that an application might want to process the image
  3067. differently if it is _really_ a palette color image. But we can easily add
  3068. auxiliary information that can help a TIFF reader to quickly categorize color
  3069. images if it wants to.  See the _New tags_ section below.
  3070.  
  3071.  
  3072. Benefits
  3073.  
  3074. It may be obvious, but it is probably worth discussing why we want to abolish
  3075. palette color images as a distinct classification.
  3076.  
  3077. The main problem is that palette color as a separate type makes life more
  3078. hazardous and confusing for users.  The confusion factor is aggravated because
  3079. users already have to be somewhat aware of distinctions between bilevel,
  3080. grayscale, and color images.  Having two main types of color images is hard for
  3081. many users to grasp, and it is probably not possible to totally hide this
  3082. complexity from the user in certain situations.  The hazard level goes up because
  3083. some applications may accept palette color but not full color images, or full
  3084. color but not palette color images, or may accept 8-bit palette color images but
  3085. not 4-bit or 3-bit palette color images.
  3086.  
  3087. The second problem is that writing and maintaining code to deal with an
  3088. additional image type is somewhat expensive for TIFF readers.  The cost of
  3089. supporting palette color images will depend on the application, but we believe
  3090. that, in general, the cost will be substantial.  It seems to make more sense to
  3091. put the burden on TIFF writers to convert palette color images into full color
  3092. image form than to make TIFF readers handle an additional color image type, since
  3093. there are more TIFF readers than writers at this point.
  3094.  
  3095.  
  3096. New tags
  3097.  
  3098. Here are some proposed new tags that can help to classify color images, and make
  3099. up for not having a separate palette color class.  They are not required for TIFF
  3100. Class R , but are strongly recommended for color TIFF images created by
  3101. palette-type color paint programs.
  3102.  
  3103. ColorImageType
  3104. Tag    = 318 (13E)
  3105. Type    = SHORT
  3106. N    = 1
  3107.  
  3108. Gives TIFF color image readers a better idea of what kind of color image it is. 
  3109. There will be borderline cases.
  3110.  
  3111. 1 = Continuous tone, natural image.
  3112. 2 = Synthetic image, using a greatly restricted range of colors.  Such images are
  3113. produced by most color paint programs.  See ColorList for a list of colors used
  3114. in this image.
  3115.  
  3116. Default is 1.
  3117.  
  3118. ColorList
  3119. Tag    = 319 (13F)
  3120. Type    = BYTE or SHORT
  3121. N    = the number of colors that are used in this image, times SamplesPerPixel
  3122.  
  3123. A list of colors that are used in this image.  Use of this field is only
  3124. practical for images containing a greatly restricted (usually less than or equal
  3125. to 256) range of colors.  ColorImageType should be 2.  See ColorImageType.
  3126.  
  3127. The list is organized as an array of RGB triplets, with no pad.  The RGB triplets
  3128. are not guaranteed to be in any particular order.  Note that the red, green, and
  3129. blue components can either be a BYTE or a SHORT in length.  BYTE should be
  3130. sufficient for most applications.
  3131.  
  3132. No default.
  3133.  
  3134.